37 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the vtk deprecated warning 38 #include <vtkIdTypeArray.h> 39 #include <vtkTriangle.h> 40 #include <vtkPolygon.h> 41 #include "Exception.hpp" 45 template<
unsigned DIM>
49 mVerticesUpToDate(false),
52 mReferenceLength(
BaseUnits::Instance()->GetReferenceLengthScale())
57 template<
unsigned DIM>
69 template<
unsigned DIM>
76 template<
unsigned DIM>
83 template<
unsigned DIM>
88 template<
unsigned DIM>
95 template<
unsigned DIM>
102 template<
unsigned DIM>
105 bool contains_point =
false;
106 for (
unsigned idx = 0; idx <
mPolygons.size(); idx++)
110 contains_point =
true;
114 return contains_point;
117 template<
unsigned DIM>
120 std::vector<boost::shared_ptr<DimensionalChastePoint<DIM> > > vertices =
GetVertices();
121 c_vector<double, 6> box;
123 for (
unsigned idx = 0; idx < vertices.size(); idx++)
125 c_vector<double, DIM> vertex_location = vertices[idx]->GetLocation(
mReferenceLength);
126 for (
unsigned jdx = 0; jdx < DIM; jdx++)
130 box[2 * jdx] = vertex_location[jdx];
131 box[2 * jdx + 1] = vertex_location[jdx];
135 if (vertex_location[jdx] < box[2 * jdx])
137 box[2 * jdx] = vertex_location[jdx];
139 if (vertex_location[jdx] > box[2 * jdx + 1])
141 box[2 * jdx + 1] = vertex_location[jdx];
147 std::vector<units::quantity<unit::length> > box_vector(6);
148 for(
unsigned idx=0; idx<6; idx++)
156 template<
unsigned DIM>
160 std::pair<vtkSmartPointer<vtkPoints>, vtkSmartPointer<vtkIdTypeArray> > vertex_data =
GetVtkVertices();
161 vtkPolygon::ComputeCentroid(vertex_data.second, vertex_data.first, centroid);
162 c_vector<double, DIM> return_centroid;
163 for (
unsigned idx = 0; idx < DIM; idx++)
165 return_centroid[idx] = centroid[idx];
177 template<
unsigned DIM>
183 template<
unsigned DIM>
186 double location_array[3];
187 for(
unsigned idx=0; idx<DIM;idx++)
193 location_array[2] = 0.0;
196 vtkSmartPointer<vtkPlane> p_plane =
GetPlane();
197 double distance = p_plane->DistanceToPlane(&location_array[0]);
201 template<
unsigned DIM>
204 std::vector<boost::shared_ptr<DimensionalChastePoint<DIM> > > vertices =
GetVertices();
205 if (vertices.size() < 3)
207 EXCEPTION(
"At least 3 vertices are required to generate a normal.");
210 std::pair<vtkSmartPointer<vtkPoints>, vtkSmartPointer<vtkIdTypeArray> > vertex_data =
GetVtkVertices();
214 vertex_data.first->GetPoint(0, loc1);
215 vertex_data.first->GetPoint(1, loc2);
216 vertex_data.first->GetPoint(2, loc3);
217 c_vector<double, 3> normal;
218 vtkTriangle::ComputeNormal(loc1, loc2, loc3, &normal[0]);
225 c_vector<double, 2> normal_2d;
226 normal_2d[0] = normal[0];
227 normal_2d[1] = normal[1];
232 template<
unsigned DIM>
235 vtkSmartPointer<vtkPlane> p_plane = vtkSmartPointer<vtkPlane>::New();
237 c_vector<double, DIM> normal =
GetNormal();
240 p_plane->SetOrigin(centroid[0], centroid[1], centroid[2]);
241 p_plane->SetNormal(normal[0], normal[1], normal[2]);
245 p_plane->SetOrigin(centroid[0], centroid[1], 0.0);
246 p_plane->SetNormal(normal[0], normal[1], 0.0);
251 template<
unsigned DIM>
257 template<
unsigned DIM>
267 template<
unsigned DIM>
270 vtkSmartPointer<vtkIdTypeArray> p_vertexIds = vtkSmartPointer<vtkIdTypeArray>::New();
271 vtkSmartPointer<vtkPoints> p_vertices = vtkSmartPointer<vtkPoints>::New();
272 std::vector<boost::shared_ptr<DimensionalChastePoint<DIM> > > vertices =
GetVertices();
274 p_vertices->SetNumberOfPoints(vertices.size());
275 for (vtkIdType idx = 0; idx < vtkIdType(vertices.size()); idx++)
277 c_vector<double, DIM> vertex_location = vertices[idx]->GetLocation(
mReferenceLength);
280 p_vertices->SetPoint(idx, vertex_location[0], vertex_location[1], vertex_location[2]);
284 p_vertices->SetPoint(idx, vertex_location[0], vertex_location[1], 0.0);
286 p_vertexIds->InsertNextValue(idx);
288 return std::pair<vtkSmartPointer<vtkPoints>, vtkSmartPointer<vtkIdTypeArray> >(p_vertices, p_vertexIds);
291 template<
unsigned DIM>
294 std::vector<boost::shared_ptr<DimensionalChastePoint<DIM> > > vertices =
GetVertices();
295 for(
unsigned idx=0; idx<vertices.size(); idx++)
297 vertices[idx]->RotateAboutAxis(axis, angle);
301 template<
unsigned DIM>
307 template<
unsigned DIM>
310 std::vector<boost::shared_ptr<DimensionalChastePoint<DIM> > > vertices =
GetVertices();
311 for(
unsigned idx=0; idx<vertices.size(); idx++)
313 vertices[idx]->Translate(translationVector);
317 template<
unsigned DIM>
320 std::set<boost::shared_ptr<DimensionalChastePoint<DIM> > > unique_vertices;
321 for (
unsigned idx = 0; idx <
mPolygons.size(); idx++)
323 std::vector<boost::shared_ptr<DimensionalChastePoint<DIM> > > polygon_vertices =
mPolygons[idx]->GetVertices();
324 std::copy(polygon_vertices.begin(), polygon_vertices.end(),
325 std::inserter(unique_vertices, unique_vertices.end()));
327 mVertices = std::vector<boost::shared_ptr<DimensionalChastePoint<DIM> > >();
330 for (
unsigned idx = 0; idx <
mVertices.size(); idx++)
void AddPolygon(boost::shared_ptr< Polygon< DIM > > pPolygon)
std::vector< boost::shared_ptr< Polygon< DIM > > > mPolygons
Facet(std::vector< boost::shared_ptr< Polygon< DIM > > > polygons)
std::pair< vtkSmartPointer< vtkPoints >, vtkSmartPointer< vtkIdTypeArray > > GetVtkVertices()
void AddPolygons(std::vector< boost::shared_ptr< Polygon< DIM > > > polygons)
bool ContainsPoint(const DimensionalChastePoint< DIM > &location)
std::map< std::string, double > mData
std::vector< boost::shared_ptr< Polygon< DIM > > > GetPolygons()
static boost::shared_ptr< Facet< DIM > > Create(std::vector< boost::shared_ptr< Polygon< DIM > > > polygons)
vtkSmartPointer< vtkPlane > GetPlane()
c_vector< double, DIM > GetNormal()
void Translate(DimensionalChastePoint< DIM > translationVector)
c_vector< double, DIM > GetLocation(units::quantity< unit::length > scale)
void SetLabel(const std::string &label)
std::vector< units::quantity< unit::length > > GetBoundingBox()
void RotateAboutAxis(c_vector< double, 3 > axis, double angle)
DimensionalChastePoint< DIM > GetCentroid()
units::quantity< unit::length > mReferenceLength
std::vector< boost::shared_ptr< DimensionalChastePoint< DIM > > > mVertices
units::quantity< unit::length > GetDistance(const DimensionalChastePoint< DIM > &rLocation)
std::vector< boost::shared_ptr< DimensionalChastePoint< DIM > > > GetVertices()