fixed edge display for volume cells
[engrid-github.git] / src / libengrid / cadinterface.h
blob7d41b758379a9d9ac402be25733428abdb4b662c
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #ifndef CADINTERFACE_H
22 #define CADINTERFACE_H
24 #include "engrid.h"
25 #include "meshpartition.h"
26 #include "surfacealgorithm.h"
28 #include <QVector>
29 #include <QPair>
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
51 protected: // methods
53 /**
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();
61 /**
62 * @brief set the name
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; }
70 public: // data types
72 enum HitType { Miss, HitIn, HitOut };
75 //enum PositionType { Inside, Outside, Surface };
78 public:
80 CadInterface();
82 void setForegroundGrid(vtkUnstructuredGrid* grid);
84 QString name() { return m_Name; }
86 /**
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 snapToEdge(vec3_t x) { notImplemented(); }
125 virtual vec3_t snapToCorner(vec3_t x) { notImplemented(); }
128 * @brief snap a node of the foreground grid
129 * Curvature correction only applies to certain geometric models (e.g. STL).
130 * @param id_node the node to snap
131 * @param correct_curvature flag to determine if corveture correction shall be used
132 * @return the snapped position
134 virtual vec3_t snapNode(vtkIdType id_node, bool correct_curvature = false);
137 * @brief snap a node of the foreground grid using an alternate position
138 * Curvature correction only applies to certain geometric models (e.g. STL).
139 * @param id_node the node to snap
140 * @param x the position to snap
141 * @param correct_curvature flag to determine if curvature correction shall be used
142 * @return the snapped position
144 virtual vec3_t snapNode(vtkIdType id_node, vec3_t x, bool correct_curvature = false);
147 * @brief project a point onto the geometry
148 * If you want to project a node of the mesh, consider using projectNode because it might be faster.
149 * This methods project in forward and backward direction and takes the closer point.
150 * Curvature correction only applies to certain geometric models (e.g. STL).
151 * @param x the position of the point to project
152 * @param v the direction of projection
153 * @param strict_direction if set to true only the forward direction will be considered
154 * @param correct_curvature set this to true if you want to use curvature correction
155 * @return the projected point
157 virtual vec3_t project(vec3_t x, vec3_t v, bool strict_direction = false, bool correct_curvature = false);
160 * @brief project a node of the foreground mesh onto the geometry
161 * This methods project in forward and backward direction and takes the closer point.
162 * Curvature correction only applies to certain geometric models (e.g. STL).
163 * @param id_node the node to project
164 * @param strict_direction if set to true only the forward direction will be considered
165 * @param correct_curvature set this to true if you want to use curvature correction
166 * @return the projected point
168 virtual vec3_t projectNode(vtkIdType id_node, bool strict_direction = false, bool correct_curvature = false);
171 * @brief project a node of the foreground mesh onto the geometry using an alternate position
172 * This methods project in forward and backward direction and takes the closer point.
173 * Curvature correction only applies to certain geometric models (e.g. STL).
174 * @param id_node the node to project
175 * @param x the position to project
176 * @param strict_direction if set to true only the forward direction will be considered
177 * @param correct_curvature set this to true if you want to use curvature correction
178 * @return the projected point
180 virtual vec3_t projectNode(vtkIdType id_node, vec3_t x, bool strict_direction = false, bool correct_curvature = false);
183 * @brief project a node of the foreground mesh onto the geometry using an alternate position and direction
184 * This methods project in forward and backward direction and takes the closer point.
185 * Curvature correction only applies to certain geometric models (e.g. STL).
186 * @param id_node the node to project
187 * @param x the position to project
188 * @param v the direction of projection
189 * @param strict_direction if set to true only the forward direction will be considered
190 * @param correct_curvature set this to true if you want to use curvature correction
191 * @return the projected point
193 virtual vec3_t projectNode(vtkIdType id_node, vec3_t x, vec3_t v, bool strict_direction = false, bool correct_curvature = false);
195 virtual vec3_t correctCurvature(vec3_t x) { return x; }
197 virtual double getRadius(vtkIdType id_node);
199 //vtkIdType lastProjTriangle() { return -1; } /// delete this ???
201 bool failed() { return m_Failed; }
202 vec3_t getLastNormal() { return m_LastNormal; }
203 double getLastRadius() { return m_LastRadius; }
207 #endif // CADINTERFACE_H