1 #ifndef FILE_SOLID
2 #define FILE_SOLID
3 
4 /**************************************************************************/
5 /* File:   solid.hh                                                       */
6 /* Author: Joachim Schoeberl                                              */
7 /* Date:   1. Dez. 95                                                     */
8 /**************************************************************************/
9 
10 namespace netgen
11 {
12 
13 
14   /*
15 
16   Constructive Solid Model (csg)
17 
18   */
19 
20 
21 
22 
23   class Solid;
24 
25   class SolidIterator
26   {
27   public:
SolidIterator()28     SolidIterator () { ; }
~SolidIterator()29     virtual ~SolidIterator () { ; }
30     virtual void Do (Solid * sol) = 0;
31   };
32 
33 
34 
35   class Solid
36   {
37   public:
38 
39     typedef enum optyp1 { TERM, TERM_REF, SECTION, UNION, SUB, ROOT /*, DUMMY */ } optyp;
40 
41   private:
42     char * name;
43     Primitive * prim;
44     Solid * s1, * s2;
45 
46     optyp op;
47     bool visited;
48     double maxh;
49 
50     // static int cntnames;
51 
52   public:
53     Solid (Primitive * aprim);
54     Solid (optyp aop, Solid * as1, Solid * as2 = NULL);
55     ~Solid ();
56 
Name() const57     const char * Name () const { return name; }
58     void SetName (const char * aname);
59 
60     Solid * Copy (class CSGeometry & geom) const;
61     void Transform (Transformation<3> & trans);
62 
63 
64     void IterateSolid (SolidIterator & it, bool only_once = 0);
65 
66 
67     void Boundaries (const Point<3> & p, Array<int> & bounds) const;
68     int NumPrimitives () const;
69     void GetSurfaceIndices (Array<int> & surfind) const;
70     void GetSurfaceIndices (IndexSet & iset) const;
71 
72     void GetTangentialSurfaceIndices (const Point<3> & p, Array<int> & surfids, double eps) const;
73     void GetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, Array<int> & surfids, double eps) const;
74     void GetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, Array<int> & surfids, double eps) const;
75 
76 
GetPrimitive()77     Primitive * GetPrimitive ()
78     { return (op == TERM || op == TERM_REF) ? prim : NULL; }
GetPrimitive() const79     const Primitive * GetPrimitive () const
80     { return (op == TERM || op == TERM_REF) ? prim : NULL; }
81 
S1()82     Solid * S1() { return s1; }
S2()83     Solid * S2() { return s2; }
84 
85     // geometric tests
86 
87     bool IsIn (const Point<3> & p, double eps = 1e-6) const;
88     bool IsStrictIn (const Point<3> & p, double eps = 1e-6) const;
89     bool VectorIn (const Point<3> & p, const Vec<3> & v, double eps = 1e-6) const;
90     bool VectorStrictIn (const Point<3> & p, const Vec<3> & v, double eps = 1e-6) const;
91 
92     bool VectorIn2 (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2,
93 		    double eps) const;
94     bool VectorIn2Rec (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2,
95 		       double eps) const;
96 
97 
98     /// compute localization in point p
99     void TangentialSolid (const Point<3> & p, Solid *& tansol, Array<int> & surfids, double eps) const;
100 
101     /// compute localization in point p tangential to vector t
102     void TangentialSolid2 (const Point<3> & p, const Vec<3> & t,
103 			   Solid *& tansol, Array<int> & surfids, double eps) const;
104 
105     /** compute localization in point p, with second order approximation to edge
106 	p + s t + s*s/2 t2 **/
107     void TangentialSolid3 (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2,
108 			   Solid *& tansol, Array<int> & surfids, double eps) const;
109 
110 
111 
112     /** tangential solid, which follows the edge
113 	p + s t + s*s/2 t2
114 	with second order, and the neighbouring face
115 	p + s t + s*s/2 t2 + r m
116 	with first order
117     **/
118     void TangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2,
119 			      const Vec<3> & m,
120 			      Solid *& tansol, Array<int> & surfids, double eps) const;
121 
122 
123     void CalcOnePrimitiveSpecialPoints (const Box<3> & box, Array<Point<3> > & pts) const;
124 
125     ///
126     int Edge (const Point<3> & p, const Vec<3> & v, double eps) const;
127     ///
128     int OnFace (const Point<3> & p, const Vec<3> & v, double eps) const;
129     ///
130     void Print (ostream & str) const;
131     ///
132     void CalcSurfaceInverse ();
133     ///
134     Solid * GetReducedSolid (const BoxSphere<3> & box) const;
135 
136 
SetMaxH(double amaxh)137     void SetMaxH (double amaxh)
138     { maxh = amaxh; }
GetMaxH() const139     double GetMaxH () const
140     { return maxh; }
141 
142     void GetSolidData (ostream & ost, int first = 1) const;
143     static Solid * CreateSolid (istream & ist, const SYMBOLTABLE<Solid*> & solids);
144 
145 
146     static BlockAllocator ball;
operator new(size_t)147     void * operator new(size_t /* s */)
148     {
149       return ball.Alloc();
150     }
151 
operator delete(void * p)152     void operator delete (void * p)
153     {
154       ball.Free (p);
155     }
156 
157 
158   protected:
159     ///
160 
161     void RecBoundaries (const Point<3> & p, Array<int> & bounds,
162 			int & in, int & strin) const;
163     ///
164     void RecTangentialSolid (const Point<3> & p, Solid *& tansol, Array<int> & surfids,
165 			     int & in, int & strin, double eps) const;
166 
167     void RecTangentialSolid2 (const Point<3> & p, const Vec<3> & vec,
168 			      Solid *& tansol, Array<int> & surfids,
169 			      int & in, int & strin, double eps) const;
170     ///
171     void RecTangentialSolid3 (const Point<3> & p, const Vec<3> & vec,const Vec<3> & vec2,
172 			      Solid *& tansol, Array<int> & surfids,
173 			      int & in, int & strin, double eps) const;
174     ///
175     void RecTangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2,
176 				 const Vec<3> & m,
177 				 Solid *& tansol, Array<int> & surfids,
178 				 int & in, int & strin, double eps) const;
179 
180     ///
181     void RecEdge (const Point<3> & p, const Vec<3> & v,
182 		  int & in, int & strin, int & faces, double eps) const;
183     ///
184     void CalcSurfaceInverseRec (int inv);
185     ///
186     Solid * RecGetReducedSolid (const BoxSphere<3> & box, INSOLID_TYPE & in) const;
187     ///
188     void RecGetSurfaceIndices (Array<int> & surfind) const;
189     void RecGetTangentialSurfaceIndices (const Point<3> & p, Array<int> & surfids, double eps) const;
190     void RecGetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, Array<int> & surfids, double eps) const;
191     void RecGetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2,
192 					  Array<int> & surfids, double eps) const;
193     void RecGetTangentialEdgeSurfaceIndices (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, const Vec<3> & m,
194 					     Array<int> & surfids, double eps) const;
195     void RecGetSurfaceIndices (IndexSet & iset) const;
196 
197     void RecCalcOnePrimitiveSpecialPoints (Array<Point<3> > & pts) const;
198 
199     friend class SolidIterator;
200     friend class ClearVisitedIt;
201     friend class RemoveDummyIterator;
202     friend class CSGeometry;
203   };
204 
205 
operator <<(ostream & ost,const Solid & sol)206   inline ostream & operator<< (ostream & ost, const Solid & sol)
207   {
208     sol.Print (ost);
209     return ost;
210   }
211 
212 
213 
214 
215 
216 
217   class ReducePrimitiveIterator : public SolidIterator
218   {
219     const BoxSphere<3> & box;
220   public:
ReducePrimitiveIterator(const BoxSphere<3> & abox)221     ReducePrimitiveIterator (const BoxSphere<3> & abox)
222       : SolidIterator(), box(abox) { ; }
~ReducePrimitiveIterator()223     virtual ~ReducePrimitiveIterator () { ; }
Do(Solid * sol)224     virtual void Do (Solid * sol)
225     {
226       if (sol -> GetPrimitive())
227 	sol -> GetPrimitive() -> Reduce (box);
228     }
229   };
230 
231 
232   class UnReducePrimitiveIterator : public SolidIterator
233   {
234   public:
UnReducePrimitiveIterator()235     UnReducePrimitiveIterator () { ; }
~UnReducePrimitiveIterator()236     virtual ~UnReducePrimitiveIterator () { ; }
Do(Solid * sol)237     virtual void Do (Solid * sol)
238     {
239       if (sol -> GetPrimitive())
240 	sol -> GetPrimitive() -> UnReduce ();
241     }
242   };
243 
244 }
245 
246 #endif
247