1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #ifndef CADINTERFACE_H
22 #define CADINTERFACE_H
25 #include "meshpartition.h"
26 #include "surfacealgorithm.h"
31 class CadInterface
: public SurfaceAlgorithm
34 private: // attributes
36 QString m_Name
; ///< The name of the CAD interface
39 protected: // attributes
41 vtkUnstructuredGrid
* m_FGrid
; ///< the foreground grid to project
42 MeshPartition m_FPart
; ///< MeshPartition for the foreground grid
43 QVector
<vec3_t
> m_RayPoints
; ///< template for ray cloud to snap points
44 vec3_t m_LastNormal
; ///< last surface normal which was encountered
45 double m_LastRadius
; ///< last surface radius which was encountered
46 bool m_Failed
; ///< did the last operation fail
47 bool m_ShootRayImplemented
; ///< flag to determine if shootRay has been implemented
48 double m_CriticalSnapLength
; ///< relative distance to decide between project or real snap
54 * @brief issue an error message about not implemented functionality
55 * Not all functionality will be implemented in every derived class of CadInterface.
56 * Certain meshing processes might still work. For this reason an error message will be displayed,
57 * rather than preventing instantiation by using abstract methods (=0).
59 void notImplemented();
63 * The CAD interface should be given a name. This will be used to display messages.
64 * A name could, for example, be "triangulated geometry CAD interface".
65 * @param name the name to set
67 void setName(QString name
) { m_Name
= name
; }
72 enum HitType
{ Miss
, HitIn
, HitOut
};
75 //enum PositionType { Inside, Outside, Surface };
82 void setForegroundGrid(vtkUnstructuredGrid
* grid
);
84 QString
name() { return m_Name
; }
87 * @brief vital interface method to the geometry
88 * This method is a major part of interfacing geometries. The idea is to provide something like
89 * a virtual laser scanner. The concept of a ray-tracing interface has been taken from the
90 * open-source CAD software BRL-CAD (see http://brlcad.org).
91 * @param x the origin of the ray
92 * @param v the direction of the ray
93 * @param x_hit if the ray hits this contains the intersection point between ray and geometry
94 * @param n_hit if the ray hits this contains the geometry normal vector at the intersection point
95 * @param r if the ray hits this contains the surface radius at the intersection point
96 * @return the result (Miss, HitIn, HitOut)
98 virtual HitType
shootRay(vec3_t x
, vec3_t v
, vec3_t
&x_hit
, vec3_t
&n_hit
, double &r
);
101 * @brief compute all intersections of a ray and the CAD geometry.
102 * @param x the origin of the ray
103 * @param v the direction of the ray
104 * @param intersections will hold all intersections with the goemtry
106 virtual void computeIntersections(vec3_t x
, vec3_t v
, QVector
<QPair
<vec3_t
,vtkIdType
> > &intersections
) { notImplemented(); }
109 * @brief check if shootRay is available (implemented)
110 * @return true id shootRay is available
112 bool shootRayAvailable() { return m_ShootRayImplemented
; }
115 * @brief snap a point to the geometry
116 * If you want to snap a node of the grid, consider using snapNode because it might be faster.
117 * Curvature correction only applies to certain geometric models (e.g. STL).
118 * @param x the position of the point to snap
119 * @param correct_curvature flag to determine if corveture correction shall be used
120 * @return the snapped position
122 virtual vec3_t
snap(vec3_t x
, bool correct_curvature
= false);
124 virtual vec3_t
snapWithNormal(vec3_t x
, vec3_t
, bool correct_curvature
= false) { return snap(x
, correct_curvature
); }
125 virtual vec3_t
snapToEdge(vec3_t x
) { notImplemented(); return vec3_t(); }
126 virtual vec3_t
snapToCorner(vec3_t x
) { notImplemented(); return vec3_t(); }
129 * @brief snap a node of the foreground grid
130 * Curvature correction only applies to certain geometric models (e.g. STL).
131 * @param id_node the node to snap
132 * @param correct_curvature flag to determine if corveture correction shall be used
133 * @return the snapped position
135 virtual vec3_t
snapNode(vtkIdType id_node
, bool correct_curvature
= false);
138 * @brief snap a node of the foreground grid using an alternate position
139 * Curvature correction only applies to certain geometric models (e.g. STL).
140 * @param id_node the node to snap
141 * @param x the position to snap
142 * @param correct_curvature flag to determine if curvature correction shall be used
143 * @return the snapped position
145 virtual vec3_t
snapNode(vtkIdType id_node
, vec3_t x
, bool correct_curvature
= false);
148 * @brief project a point onto the geometry
149 * If you want to project a node of the mesh, consider using projectNode because it might be faster.
150 * This methods project in forward and backward direction and takes the closer point.
151 * Curvature correction only applies to certain geometric models (e.g. STL).
152 * @param x the position of the point to project
153 * @param v the direction of projection
154 * @param strict_direction if set to true only the forward direction will be considered
155 * @param correct_curvature set this to true if you want to use curvature correction
156 * @return the projected point
158 virtual vec3_t
project(vec3_t x
, vec3_t v
, bool strict_direction
= false, bool correct_curvature
= false);
161 * @brief project a node of the foreground mesh onto the geometry
162 * This methods project in forward and backward direction and takes the closer point.
163 * Curvature correction only applies to certain geometric models (e.g. STL).
164 * @param id_node the node to project
165 * @param strict_direction if set to true only the forward direction will be considered
166 * @param correct_curvature set this to true if you want to use curvature correction
167 * @return the projected point
169 virtual vec3_t
projectNode(vtkIdType id_node
, bool strict_direction
= false, bool correct_curvature
= false);
172 * @brief project a node of the foreground mesh onto the geometry using an alternate position
173 * This methods project in forward and backward direction and takes the closer point.
174 * Curvature correction only applies to certain geometric models (e.g. STL).
175 * @param id_node the node to project
176 * @param x the position to project
177 * @param strict_direction if set to true only the forward direction will be considered
178 * @param correct_curvature set this to true if you want to use curvature correction
179 * @return the projected point
181 virtual vec3_t
projectNode(vtkIdType id_node
, vec3_t x
, bool strict_direction
= false, bool correct_curvature
= false);
184 * @brief project a node of the foreground mesh onto the geometry using an alternate position and direction
185 * This methods project in forward and backward direction and takes the closer point.
186 * Curvature correction only applies to certain geometric models (e.g. STL).
187 * @param id_node the node to project
188 * @param x the position to project
189 * @param v the direction of projection
190 * @param strict_direction if set to true only the forward direction will be considered
191 * @param correct_curvature set this to true if you want to use curvature correction
192 * @return the projected point
194 virtual vec3_t
projectNode(vtkIdType id_node
, vec3_t x
, vec3_t v
, bool strict_direction
= false, bool correct_curvature
= false);
196 virtual vec3_t
correctCurvature(vec3_t x
) { return x
; }
198 virtual double getRadius(vtkIdType id_node
);
200 //vtkIdType lastProjTriangle() { return -1; } /// delete this ???
202 bool failed() { return m_Failed
; }
203 vec3_t
getLastNormal() { return m_LastNormal
; }
204 double getLastRadius() { return m_LastRadius
; }
208 #endif // CADINTERFACE_H