38 #include "UblasIncludes.hpp" 39 #include "Polygon.hpp" 40 #include "DimensionalChastePoint.hpp" 41 #include "MappableGridGenerator.hpp" 42 #include "BaseUnits.hpp" 45 mReferenceLength(
BaseUnits::Instance()->GetReferenceLengthScale())
58 std::vector<boost::shared_ptr<DimensionalChastePoint<3> > > vertices;
59 for(
unsigned jdx=0; jdx< numY; jdx++)
61 for(
unsigned idx=0; idx<numX; idx++)
63 double x_location = double(idx);
64 double y_location = double(jdx);
65 double z_location = 0.0;
73 for(
unsigned jdx=0; jdx< numY; jdx++)
75 for(
unsigned idx=0; idx<numX; idx++)
77 double x_location = double(idx);
78 double y_location = double(jdx);
79 double z_location = 1.0;
89 std::vector<boost::shared_ptr<Polygon<3> > > polygons;
90 for(
unsigned jdx=0; jdx< numY - 1; jdx++)
92 for(
unsigned idx=0; idx<numX - 1; idx++)
94 unsigned front_left_index = idx + numX * jdx;
95 unsigned front_right_index = idx + 1 + numX * jdx;
96 unsigned front_left_top_index = idx + numX * (jdx+1);
97 unsigned front_right_top_index = idx + 1 + numX * (jdx+1);
99 std::vector<boost::shared_ptr<DimensionalChastePoint<3> > > poly_vertices;
100 poly_vertices.push_back(vertices[front_left_index]);
101 poly_vertices.push_back(vertices[front_right_index]);
102 poly_vertices.push_back(vertices[front_right_top_index]);
103 poly_vertices.push_back(vertices[front_left_top_index]);
109 for(
unsigned jdx=0; jdx< numY - 1; jdx++)
111 for(
unsigned idx=0; idx<numX - 1; idx++)
113 unsigned front_left_index = idx + numX * jdx + numX*numY;
114 unsigned front_right_index = idx + 1 + numX * jdx + numX*numY;
115 unsigned front_left_top_index = idx + numX * (jdx+1) + numX*numY;
116 unsigned front_right_top_index = idx + 1 + numX * (jdx+1) + numX*numY;
118 std::vector<boost::shared_ptr<DimensionalChastePoint<3> > > poly_vertices;
119 poly_vertices.push_back(vertices[front_left_index]);
120 poly_vertices.push_back(vertices[front_right_index]);
121 poly_vertices.push_back(vertices[front_right_top_index]);
122 poly_vertices.push_back(vertices[front_left_top_index]);
130 for(
unsigned jdx=0; jdx< numY - 1; jdx++)
132 unsigned front_index = numX * jdx;
133 unsigned top_front_index = numX * (jdx+1);
134 unsigned back_index = numX * jdx + numX*numY;
135 unsigned top_back_index = numX * (jdx+1) + numX*numY;
137 std::vector<boost::shared_ptr<DimensionalChastePoint<3> > > poly_vertices;
138 poly_vertices.push_back(vertices[front_index]);
139 poly_vertices.push_back(vertices[top_front_index]);
140 poly_vertices.push_back(vertices[top_back_index]);
141 poly_vertices.push_back(vertices[back_index]);
146 for(
unsigned jdx=0; jdx< numY - 1; jdx++)
148 unsigned front_index = numX * (jdx+1) - 1;
149 unsigned top_front_index = numX * (jdx+2) - 1;
150 unsigned back_index = numX * (jdx + 1) - 1 + numX*numY;
151 unsigned top_back_index = numX * (jdx+2) -1 + numX*numY;
153 std::vector<boost::shared_ptr<DimensionalChastePoint<3> > > poly_vertices;
154 poly_vertices.push_back(vertices[front_index]);
155 poly_vertices.push_back(vertices[top_front_index]);
156 poly_vertices.push_back(vertices[top_back_index]);
157 poly_vertices.push_back(vertices[back_index]);
163 for(
unsigned idx=0; idx< numX - 1; idx++)
165 unsigned front_index = idx;
166 unsigned front_right_index = idx + 1;
167 unsigned back_index = idx + numX*numY;
168 unsigned back_right_index = idx + 1 + numX*numY;
170 std::vector<boost::shared_ptr<DimensionalChastePoint<3> > > poly_vertices;
171 poly_vertices.push_back(vertices[front_index]);
172 poly_vertices.push_back(vertices[front_right_index]);
173 poly_vertices.push_back(vertices[back_right_index]);
174 poly_vertices.push_back(vertices[back_index]);
179 for(
unsigned idx=0; idx< numX - 1; idx++)
181 unsigned front_index = idx + numX*(numY-1);
182 unsigned front_right_index = idx + 1 + numX*(numY-1);
183 unsigned back_index = idx + + numX*(numY-1) + numX*numY;
184 unsigned back_right_index = idx + numX*(numY-1) + 1 + numX*numY;
186 std::vector<boost::shared_ptr<DimensionalChastePoint<3> > > poly_vertices;
187 poly_vertices.push_back(vertices[front_index]);
188 poly_vertices.push_back(vertices[front_right_index]);
189 poly_vertices.push_back(vertices[back_right_index]);
190 poly_vertices.push_back(vertices[back_index]);
196 for(
unsigned idx=0; idx<polygons.size(); idx++)
198 p_part->AddPolygon(polygons[idx],
true);
204 double cylinderThickness,
205 double cylinderHeight,
208 double cylinderAngle)
210 if(cylinderAngle > 2.0 * M_PI)
212 EXCEPTION(
"The cylinder angle should be <= 2*pi");
215 boost::shared_ptr<Part<3> > p_part =
GeneratePlane(numX, numY, !(cylinderAngle == 2.0 * M_PI));
218 std::vector<units::quantity<unit::length> > bbox = p_part->GetBoundingBox();
221 std::vector<boost::shared_ptr<DimensionalChastePoint<3> > > vertices = p_part->GetVertices();
222 for(
unsigned idx =0; idx<vertices.size(); idx++)
224 c_vector<double, 3> vertex_location = vertices[idx]->GetLocation(
mReferenceLength);
226 double angle = x_frac * cylinderAngle;
229 double height = y_frac * cylinderHeight;
232 double radius = cylinderRadius - cylinderThickness * z_frac;
235 c_vector<double, 3> new_position;
236 new_position[0] = radius * std::cos(angle);
239 new_position[1] = height;
242 new_position[2] = radius * std::sin(angle);
246 p_part->MergeCoincidentVertices();
251 double sphereThickness,
254 double sphereAzimuthAngle,
255 double spherePolarAngle)
257 if(sphereAzimuthAngle >= 2.0 * M_PI)
259 EXCEPTION(
"The azimuth angle should be < 2*pi");
262 if(spherePolarAngle >= M_PI)
264 EXCEPTION(
"The polar angle should be < pi");
267 boost::shared_ptr<Part<3> > p_part =
GeneratePlane(numX, numY);
270 std::vector<units::quantity<unit::length> > bbox = p_part->GetBoundingBox();
273 std::vector<boost::shared_ptr<DimensionalChastePoint<3> > > vertices = p_part->GetVertices();
274 for(
unsigned idx =0; idx<vertices.size(); idx++)
276 c_vector<double, 3> vertex_location = vertices[idx]->GetLocation(
mReferenceLength);
278 double azimuth_angle = x_frac * sphereAzimuthAngle;
281 double polar_angle = y_frac * spherePolarAngle;
284 double radius = sphereRadius - sphereThickness * z_frac;
287 c_vector<double, 3> new_position;
288 new_position[0] = radius * std::cos(azimuth_angle) * std::sin(polar_angle);
291 new_position[1] = radius * std::cos(polar_angle);
294 new_position[2] = radius * std::sin(azimuth_angle) * std::sin(polar_angle);
299 p_part->MergeCoincidentVertices();
boost::shared_ptr< Part< 3 > > GenerateCylinder(double cylinderRadius, double cylinderThickness, double cylinderHeight, unsigned numX, unsigned numY, double cylinderAngle=2.0 *M_PI)
boost::shared_ptr< Part< 3 > > GenerateHemisphere(double sphereRadius, double sphereThickness, unsigned numX, unsigned numY, double sphereAzimuthAngle=2.0 *M_PI, double spherePolarAngle=0.5 *M_PI)
static boost::shared_ptr< Part< DIM > > Create()
boost::shared_ptr< Part< 3 > > GeneratePlane(unsigned numX, unsigned numY, bool withEndCaps=true)
units::quantity< unit::length > mReferenceLength