MPQC  3.0.0-alpha
surf.h
1 //
2 // surf.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _math_isosurf_surf_h
29 #define _math_isosurf_surf_h
30 
31 #ifdef HAVE_CONFIG_H
32 #include <mpqc_config.h>
33 #endif
34 
35 #include <map>
36 #include <set>
37 #include <vector>
38 
39 #include <math/isosurf/triangle.h>
40 #include <math/isosurf/volume.h>
41 #include <util/render/render.h>
42 
43 namespace sc {
44 
45 template <class C, class I>
46 inline void
47 erase_elements_by_value(C &container, I begin, I end)
48 {
49  for (I i=begin; i!=end; i++) {
50  container.erase(*i);
51  }
52 }
53 
55  protected:
56  int _verbose;
57  int _debug;
58 
59  int _completed_surface;
60 
61  // sets of objects that make up the surface
62  std::set<Ref<Vertex> > _vertices;
63  std::set<Ref<Edge> > _edges;
64  std::set<Ref<Triangle> > _triangles;
65 
66  // map objects to an integer index
67  std::map<Ref<Vertex>,int> _vertex_to_index;
68  std::map<Ref<Edge>,int> _edge_to_index;
69  std::map<Ref<Triangle>,int> _triangle_to_index;
70 
71  // map integer indices to an object
72  std::vector<Ref<Vertex> > _index_to_vertex;
73  std::vector<Ref<Edge> > _index_to_edge;
74  std::vector<Ref<Triangle> > _index_to_triangle;
75 
76  // mappings between array element numbers
77  int** _triangle_vertex;
78  int** _triangle_edge;
79  int** _edge_vertex;
80 
81  // values for each of the vertices
82  int _have_values;
83  std::vector<double> _values;
84 
85  // what to use to integrate over the surface, by default
86  Ref<TriangleIntegrator> _integrator;
87  // other integrators, in terms of time & accuracy:
88  // _fast_integrator <= _integrator <= _accurate_interator
89  Ref<TriangleIntegrator> _fast_integrator;
90  Ref<TriangleIntegrator> _accurate_integrator;
91 
92  void clear_int_arrays();
93 
94  void complete_ref_arrays();
95  void complete_int_arrays();
96 
97  void recompute_index_maps();
98 
99  void add_triangle(const Ref<Triangle>&);
100  void add_vertex(const Ref<Vertex>&);
101  void add_edge(const Ref<Edge>&);
102 
103  // these members must be used to allocate new triangles and edges
104  // since specializations of TriangulatedSurface might need to
105  // override these to produce triangles and edges with interpolation
106  // data.
107  virtual Triangle* newTriangle(const Ref<Edge>&,
108  const Ref<Edge>&,
109  const Ref<Edge>&,
110  int orientation) const;
111  virtual Edge* newEdge(const Ref<Vertex>&,const Ref<Vertex>&) const;
112 
113  // this map of edges to vertices is used to construct the surface
114  std::map<Ref<Vertex>,std::set<Ref<Edge> > > _tmp_edges;
115  public:
118  virtual ~TriangulatedSurface();
119 
120  // control printing
121  int verbose() const { return _verbose; }
122  void verbose(int v) { _verbose = v; }
123 
124  // set up an integrator
125  void set_integrator(const Ref<TriangleIntegrator>&);
126  void set_fast_integrator(const Ref<TriangleIntegrator>&);
127  void set_accurate_integrator(const Ref<TriangleIntegrator>&);
128  virtual Ref<TriangleIntegrator> integrator(int itri);
129  virtual Ref<TriangleIntegrator> fast_integrator(int itri);
130  virtual Ref<TriangleIntegrator> accurate_integrator(int itri);
131 
132  // construct the surface
133  void add_triangle(const Ref<Vertex>&,
134  const Ref<Vertex>&,
135  const Ref<Vertex>&);
136  Ref<Edge> find_edge(const Ref<Vertex>&, const Ref<Vertex>&);
137  virtual void complete_surface();
138 
139  // clean up the surface
140  virtual void remove_short_edges(double cutoff_length = 1.0e-6,
141  const Ref<Volume> &vol=0, double isoval=0.0);
142  virtual void remove_slender_triangles(
143  int remove_slender, double height_cutoff,
144  int remove_small, double area_cutoff,
145  const Ref<Volume> &vol=0, double isoval=0.0);
146  virtual void fix_orientation();
147  virtual void clear();
148 
149  // get information from the object sets
150  int nvertex() const { return _vertices.size(); };
151  Ref<Vertex> vertex(int i) const { return _index_to_vertex[i]; };
152  int vertex_index(const Ref<Vertex> &o) {
153  std::map<Ref<Vertex>,int>::iterator i = _vertex_to_index.find(o);
154  if (i != _vertex_to_index.end()) return i->second;
155  return -1;
156  }
157  int nedge() const { return _edges.size(); };
158  Ref<Edge> edge(int i) const { return _index_to_edge[i]; };
159  int edge_index(const Ref<Edge> &o) {
160  std::map<Ref<Edge>,int>::iterator i = _edge_to_index.find(o);
161  if (i != _edge_to_index.end()) return i->second;
162  return -1;
163  }
164  int ntriangle() const { return _triangles.size(); };
165  Ref<Triangle> triangle(int i) const { return _index_to_triangle[i]; }
166  int triangle_index(const Ref<Triangle> &o) {
167  std::map<Ref<Triangle>,int>::iterator i = _triangle_to_index.find(o);
168  if (i != _triangle_to_index.end()) return i->second;
169  return -1;
170  }
171 
172  // information from the index mappings
173  int triangle_vertex(int i,int j) const { return _triangle_vertex[i][j]; };
174  int triangle_edge(int i,int j) const { return _triangle_edge[i][j]; };
175  int edge_vertex(int i,int j) const { return _edge_vertex[i][j]; };
176 
177  // associate values with vertices
178  //void compute_colors(Volume&);
179  void compute_values(Ref<Volume>&);
180 
181  // properties of the surface
182  virtual double flat_area(); // use flat triangles
183  virtual double flat_volume(); // use flat triangles
184  virtual double area();
185  virtual double volume();
186 
187  // output of the surface
188  virtual void print(std::ostream&o=ExEnv::out0()) const;
189  virtual void print_vertices_and_triangles(std::ostream&o=ExEnv::out0()) const;
190  virtual void print_geomview_format(std::ostream&o=ExEnv::out0()) const;
191  virtual void render(const Ref<Render> &render);
192 
193  // print information about the topology
194  void topology_info(std::ostream&o=ExEnv::out0());
195  void topology_info(int nvertex, int nedge, int ntri, std::ostream&o=ExEnv::out0());
196 };
197 
198 
200  private:
202  int _itri;
203  int _irs;
204  double _r;
205  double _s;
206  double _weight;
207  double _surface_element;
208  Ref<Vertex> _current;
209  SCVector3 _dA;
210  Ref<TriangleIntegrator> (TriangulatedSurface::*_integrator)(int itri);
211  Ref<MessageGrp> _grp;
212  public:
214  // the surface cannot be changed until this is destroyed
217  // Objects initialized by these operators are not automatically
218  // updated. This must be done with the update member.
219  // The _grp is not copied.
220  void operator = (const TriangulatedSurfaceIntegrator&);
222  operator = (i);
223  }
224  // Return the number of integration points.
225  int n();
226  // Assign the surface. Don't do this while iterating.
227  void set_surface(const Ref<TriangulatedSurface>&);
228  // returns the number of the vertex in the current triangle
229  int vertex_number(int i);
230  inline double r() const { return _r; }
231  inline double s() const { return _s; }
232  inline double w() const { return _weight*_surface_element; }
233  double surface_element() const { return _surface_element; }
234  double weight() const { return _weight; }
235  const SCVector3& dA() const { return _dA; }
236  Ref<Vertex> current();
237  // Tests to see if this point is valid, if it is then
238  // _r, _s, etc are computed and 1 is returned.
239  int update();
240  // This can be used to loop through unique pairs of points.
241  // The argument should be a TriangulatedSurfaceIntegrator for
242  // the same surface as this.
243  int operator < (TriangulatedSurfaceIntegrator&i) {
244  update();
245  return _itri<i._itri?1:(_itri>i._itri?0:(_irs<i._irs?1:0));
246  }
247  // Goes to the next point. Does not update.
248  void operator++();
249  inline void operator++(int) { operator++(); }
250  // setting TSI = i sets TSI to begin at the triangle i
251  int operator = (int);
252  int itri() const { return _itri; }
253  int irs() const { return _irs; }
254  // the number of points in the current triangle
255  int n_in_tri() const { return (_ts.pointer()->*_integrator)(_itri)->n(); }
256  void distribute(const Ref<MessageGrp> &);
257  void use_fast_integrator();
258  void use_accurate_integrator();
259  void use_default_integrator();
260 };
261 
263  private:
264  // The surface is defined as an isosurface of the volume vol_.
265  Ref<Volume> vol_;
266  double isovalue_;
267 
268  int fix_orientation_;
269  int remove_short_edges_;
270  double short_edge_factor_;
271  int remove_slender_triangles_;
272  double slender_triangle_factor_;
273  int remove_small_triangles_;
274  double small_triangle_factor_;
275  double resolution_;
276 
277  int order_;
278 
279  int inited_;
280  public:
283 
284  Ref<Volume> volume_object() const { return vol_; }
285  double isovalue() const { return isovalue_; }
286 
287  void init();
288  int inited() const { return inited_; }
289 };
290 
291 }
292 
293 #endif
294 
295 // Local Variables:
296 // mode: c++
297 // c-file-style: "CLJ"
298 // End:
sc::TriangulatedImplicitSurface
Definition: surf.h:262
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::Ref::pointer
T * pointer() const
Returns a pointer the reference counted object.
Definition: ref.h:413
sc::Triangle
Definition: triangle.h:36
sc::DescribedClass
Classes which need runtime information about themselves and their relationship to other classes can v...
Definition: class.h:233
sc::SCVector3
a 3-element version of SCVector
Definition: vector3.h:43
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::TriangulatedSurfaceIntegrator
Definition: surf.h:199
sc::Edge
Definition: edge.h:37
sc::TriangulatedSurface
Definition: surf.h:54
sc::TriangulatedSurface::print
virtual void print(std::ostream &o=ExEnv::out0()) const
Print the object.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:00 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.