MCPcopy Create free account
hub / github.com/MITK/MITK / GeneratePolyLine

Method GeneratePolyLine

Modules/PlanarFigure/src/DataManagement/mitkPlanarEllipse.cpp:228–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226}
227
228void mitk::PlanarEllipse::GeneratePolyLine()
229{
230 // clear the PolyLine-Contrainer, it will be reconstructed soon enough...
231 this->ClearPolyLines();
232
233 const Point2D &centerPoint = GetControlPoint(0);
234 const Point2D &boundaryPoint1 = GetControlPoint(1);
235 const Point2D &boundaryPoint2 = GetControlPoint(2);
236
237 Vector2D dir = boundaryPoint1 - centerPoint;
238 dir.Normalize();
239 vnl_matrix_fixed<float, 2, 2> rot;
240
241 // differentiate between clockwise and counterclockwise rotation
242 int start = 0;
243 int end = 64;
244 if (dir[1] < 0)
245 {
246 dir[0] = -dir[0];
247 start = -32;
248 end = 32;
249 }
250 // construct rotation matrix to align ellipse with control point vector
251 rot[0][0] = dir[0];
252 rot[1][1] = rot[0][0];
253 rot[1][0] = sin(acos(rot[0][0]));
254 rot[0][1] = -rot[1][0];
255
256 const double radius1 = centerPoint.EuclideanDistanceTo(boundaryPoint1);
257 const double radius2 = centerPoint.EuclideanDistanceTo(boundaryPoint2);
258
259 // Generate poly-line with 64 segments
260 for (int t = start; t < end; ++t)
261 {
262 const double alpha = (double)t * vnl_math::pi / 32.0;
263
264 // construct the new polyline point ...
265 vnl_vector_fixed<float, 2> vec;
266 vec[0] = radius1 * cos(alpha);
267 vec[1] = radius2 * sin(alpha);
268 vec = rot * vec;
269
270 Point2D polyLinePoint;
271 polyLinePoint[0] = centerPoint[0] + vec[0];
272 polyLinePoint[1] = centerPoint[1] + vec[1];
273
274 // ... and append it to the PolyLine.
275 // No extending supported here, so we can set the index of the PolyLineElement to '0'
276 this->AppendPointToPolyLine(0, polyLinePoint);
277 }
278
279 this->AppendPointToPolyLine(1, centerPoint);
280 this->AppendPointToPolyLine(1, this->GetControlPoint(3));
281}
282
283void mitk::PlanarEllipse::GenerateHelperPolyLine(double /*mmPerDisplayUnit*/, unsigned int /*displayHeight*/)
284{

Callers

nothing calls this directly

Calls 4

ClearPolyLinesMethod · 0.80
NormalizeMethod · 0.80
AppendPointToPolyLineMethod · 0.80
GetControlPointMethod · 0.80

Tested by

no test coverage detected