36 #define _BACKWARD_BACKWARD_WARNING_H 1 //Cut out the vtk deprecated warning 37 #include <vtkIdTypeArray.h> 38 #include <vtkTriangle.h> 39 #include <vtkDoubleArray.h> 40 #include "Exception.hpp" 41 #include "Polygon.hpp" 43 template<
unsigned DIM>
46 mReferenceLength(
BaseUnits::Instance()->GetReferenceLengthScale())
51 template<
unsigned DIM>
59 template<
unsigned DIM>
66 template<
unsigned DIM>
73 template<
unsigned DIM>
78 template<
unsigned DIM>
85 template<
unsigned DIM>
91 template<
unsigned DIM>
96 EXCEPTION(
"Requested vertex index out of range");
104 template<
unsigned DIM>
110 template<
unsigned DIM>
113 vtkSmartPointer<vtkIdTypeArray> p_vertexIds = vtkSmartPointer<vtkIdTypeArray>::New();
114 vtkSmartPointer<vtkPoints> p_vertices = vtkSmartPointer<vtkPoints>::New();
115 p_vertices->SetNumberOfPoints(
mVertices.size());
116 p_vertexIds->SetNumberOfTuples(
mVertices.size());
117 for (vtkIdType idx = 0; idx < vtkIdType(
mVertices.size()); idx++)
122 p_vertices->SetPoint(idx, vertex_location[0], vertex_location[1], vertex_location[2]);
126 p_vertices->SetPoint(idx, vertex_location[0], vertex_location[1], 0.0);
128 p_vertexIds->SetValue(idx, idx);
130 return std::pair<vtkSmartPointer<vtkPoints>, vtkSmartPointer<vtkIdTypeArray> >(p_vertices, p_vertexIds);
133 template<
unsigned DIM>
137 vtkSmartPointer<vtkPolygon> p_polygon = vtkSmartPointer<vtkPolygon>::New();
138 p_polygon->GetPoints()->SetNumberOfPoints(p_vertices->GetNumberOfPoints());
139 for (vtkIdType idx = 0; idx < p_vertices->GetNumberOfPoints(); idx++)
141 p_polygon->GetPoints()->SetPoint(idx, p_vertices->GetPoint(idx));
146 template<
unsigned DIM>
149 c_vector<double, 3> centroid;
150 std::pair<vtkSmartPointer<vtkPoints>, vtkSmartPointer<vtkIdTypeArray> > vertex_data =
GetVtkVertices();
151 vtkPolygon::ComputeCentroid(vertex_data.second, vertex_data.first, ¢roid[0]);
164 template<
unsigned DIM>
168 c_vector<double, 6> box;
169 p_polygon->GetPoints()->GetBounds(&box[0]);
171 std::vector<units::quantity<unit::length> > box_vector(6);
172 for(
unsigned idx=0; idx<6; idx++)
179 template<
unsigned DIM>
183 for (
unsigned idx = 0; idx < DIM; idx++)
192 vtkSmartPointer<vtkPlane> p_plane =
GetPlane();
193 double distance = p_plane->DistanceToPlane(&point[0]);
197 template<
unsigned DIM>
201 for (
unsigned idx = 0; idx < DIM; idx++)
214 p_polygon->GetPoints()->GetBounds(bounds);
216 double distance = p_polygon->DistanceToPolygon(
217 point, p_polygon->GetPoints()->GetNumberOfPoints(),
218 static_cast<double*
>(p_polygon->GetPoints()->GetData()->GetVoidPointer(0)), bounds, closest);
223 template<
unsigned DIM>
226 vtkSmartPointer<vtkPlane> p_plane = vtkSmartPointer<vtkPlane>::New();
228 c_vector<double, DIM> normal =
GetNormal();
231 p_plane->SetOrigin(centroid[0], centroid[1], centroid[2]);
232 p_plane->SetNormal(normal[0], normal[1], normal[2]);
236 p_plane->SetOrigin(centroid[0], centroid[1], 0.0);
237 p_plane->SetNormal(normal[0], normal[1], 0.0);
242 template<
unsigned DIM>
247 EXCEPTION(
"At least 3 vertices are required to generate a normal.");
250 std::pair<vtkSmartPointer<vtkPoints>, vtkSmartPointer<vtkIdTypeArray> > vertex_data =
GetVtkVertices();
254 vertex_data.first->GetPoint(0, loc1);
255 vertex_data.first->GetPoint(1, loc2);
256 vertex_data.first->GetPoint(2, loc3);
257 c_vector<double, 3> in_normal;
258 vtkTriangle::ComputeNormal(loc1, loc2, loc3, &in_normal[0]);
265 c_vector<double, 2> normal;
266 normal[0] = in_normal[0];
267 normal[1] = in_normal[1];
272 template<
unsigned DIM>
275 bool contains_point =
false;
280 for (
unsigned idx = 0; idx < DIM; idx++)
282 point[idx] = vertex_location[idx];
291 p_polygon->ComputeNormal(p_polygon->GetPoints()->GetNumberOfPoints(),
292 static_cast<double*
>(p_polygon->GetPoints()->GetData()->GetVoidPointer(0)), n);
295 p_polygon->GetPoints()->GetBounds(bounds);
297 int contains = p_polygon->PointInPolygon(
298 point, p_polygon->GetPoints()->GetNumberOfPoints(),
299 static_cast<double*
>(p_polygon->GetPoints()->GetData()->GetVoidPointer(0)), bounds, n);
303 contains_point =
true;
306 return contains_point;
309 template<
unsigned DIM>
314 EXCEPTION(
"Requested vertex index out of range");
322 template<
unsigned DIM>
325 for(
unsigned idx=0; idx<
mVertices.size(); idx++)
327 mVertices[idx]->RotateAboutAxis(axis, angle);
331 template<
unsigned DIM>
334 for(
unsigned idx=0; idx<
mVertices.size(); idx++)
336 mVertices[idx]->Translate(translationVector);
Polygon(std::vector< boost::shared_ptr< DimensionalChastePoint< DIM > > > vertices)
vtkSmartPointer< vtkPolygon > GetVtkPolygon()
bool ContainsPoint(const DimensionalChastePoint< DIM > &rLocation)
void AddVertex(boost::shared_ptr< DimensionalChastePoint< DIM > > pVertex)
void Translate(DimensionalChastePoint< DIM > translationVector)
units::quantity< unit::length > GetDistance(const DimensionalChastePoint< DIM > &rLocation)
static boost::shared_ptr< Polygon > Create(std::vector< boost::shared_ptr< DimensionalChastePoint< DIM > > > vertices)
void ReplaceVertex(unsigned idx, boost::shared_ptr< DimensionalChastePoint< DIM > > pVertex)
std::pair< vtkSmartPointer< vtkPoints >, vtkSmartPointer< vtkIdTypeArray > > GetVtkVertices()
c_vector< double, DIM > GetLocation(units::quantity< unit::length > scale)
std::vector< units::quantity< unit::length > > GetBoundingBox()
std::vector< boost::shared_ptr< DimensionalChastePoint< DIM > > > mVertices
void AddVertices(std::vector< boost::shared_ptr< DimensionalChastePoint< DIM > > > vertices)
units::quantity< unit::length > mReferenceLength
DimensionalChastePoint< DIM > GetCentroid()
units::quantity< unit::length > GetDistanceToEdges(const DimensionalChastePoint< DIM > &rLocation)
vtkSmartPointer< vtkPlane > GetPlane()
boost::shared_ptr< DimensionalChastePoint< DIM > > GetVertex(unsigned idx)
void RotateAboutAxis(c_vector< double, 3 > axis, double angle)
std::vector< boost::shared_ptr< DimensionalChastePoint< DIM > > > GetVertices()
c_vector< double, DIM > GetNormal()