6 #include <vtkPolyData.h> 7 #include <vtkSmartPointer.h> 8 #include <vtkCellArray.h> 13 #include <unordered_map> 38 for(
int i = 0; i < 3; i++)
40 m_points[i] = vector<T>(npoints);
42 m_initialized =
false;
66 for(
int i = 0; i < 3; i++)
68 m_points[i][idx] = pt[i];
70 m_initialized =
false;
143 assert(mask.size() == 3);
144 for(
int j = 0; j < 3; j++)
146 vector<T> newpoints(m_points[j].size());
147 int end = m_points[j].size()-1;
150 newpoints[0] = 2*mask[0] * m_points[j][1] + mask[1]*m_points[j][0];
151 newpoints[
end] = 2*mask[0] * m_points[j][end-1] + mask[1]*m_points[j][
end];
152 for(
unsigned int i = 1; i < m_points[j].size()-1; i++)
154 newpoints[i] = mask[0]*m_points[j][i-1]
155 + mask[1]*m_points[j][i]
156 + mask[2]*m_points[j][i+1];
158 m_points[j] = newpoints;
160 m_initialized =
false;
172 for(
int i = 0; i < 3; i++)
177 m_initialized =
true;
189 return m_points[0].size();
210 for(
int i = 0; i < 3; i++)
212 pt[i] = m_points[i][0];
216 for(
unsigned int i = 1; i < m_points[0].size(); i++)
218 for(
int j = 0; j < 3; j++)
220 pt[j] = m_points[j][i];
223 if(prevsign != sign){
238 nroots = findRoots(pos,plane, roots);
241 nroots = findRoots(++pos,plane,roots);
257 evaluateSingle(t,pointOnPlane);
279 for(
int i = 0; i < 3; i++)
282 = t*(m_cpoints[i][pos+1]-m_cpoints[i][pos])
283 + (1-t)*(m_cpoints[i][pos]-m_cpoints[i][pos-1]);
306 for(
int i = 0; i < 3; i++)
308 point[i] = (t*t*0.5)*m_cpoints[i][pos+1]
309 + (-(t*t)+t + 0.5) * m_cpoints[i][pos]
310 + ((1-t)*(1-t)*0.5)*m_cpoints[i][pos-1];
322 static vector<Spline3D<T> >*
323 build(vtkSmartPointer<vtkPolyData> data)
336 AdjList list(data->GetNumberOfPoints());
337 vector<Spline3D<T> > *ret =
new vector<Spline3D<T> >();
340 vtkCellArray *lines = data->GetLines();
343 vtkSmartPointer<vtkIdList> idlist = vtkSmartPointer<vtkIdList>::New();
345 while(lines->GetNextCell(idlist))
347 n_ids = idlist->GetNumberOfIds();
349 list.adjacent(idlist->GetId(0), idlist->GetId(1));
353 vector<int> stack = vector<int>();
358 vector<vector<T> > ptstack[3];
360 for(
int i = 0; i < 3; i++)
362 ptstack[i] = vector<vector<T> >();
363 ptstack[i].push_back(vector<T>());
367 vector<int> children;
375 vector<pair<int,int> > parents = vector<pair<int,int> >();
381 vector<int> firstNodes = list.findAllFirst();
383 for(
int i = firstNodes.size()-1; i >= 0; i--)
386 parents.push_back(pair<int,int>(-1, -1));
387 stack.push_back(firstNodes[i]);
391 while(!stack.empty())
395 int curnode = stack.back();
400 data->GetPoint(curnode,pt);
403 for(
int i = 0; i < 3; i++)
405 ptstack[i][curspline].push_back(pt[i]);
411 children = list.findAllNext(curnode);
412 if(children.size()!=1 && !stack.empty() )
417 parentspline = parents.back().first;
418 parentidx = parents.back().second;
421 for(
int i = 0; i < 3; i++)
423 ptstack[i].push_back(vector<T>());
429 ptstack[i][curspline].push_back(ptstack[i][parentspline][parentidx]);
434 stack.insert(stack.end(), children.begin(), children.end());
437 for(
unsigned int i = 0; i < children.size(); i++)
439 parents.push_back(pair<int,int>(curspline,ptstack[0][curspline].size()-1));
444 for(
unsigned int i = 0; i < ptstack[0].size(); i++)
446 if(ptstack[0][i].size() > 1) {
448 newspline.
setPoints(ptstack[0][i], ptstack[1][i], ptstack[2][i]);
449 ret->push_back(newspline); }
473 if(intersect(t,plane,pt))
485 derivativeSingle(t,spline_deriv);
490 for(
int i = 0; i < 3; i++)
495 for(
int i = 0; i < 3; i++)
501 double length_splinederiv =
length3d(spline_deriv);
503 T cosTheta =
innerProduct(spline_deriv, y_axis)/(length_y*length_splinederiv);
521 for(
unsigned int i = 0; i < imgs.size(); i++)
523 intersection = findIntersection(&imgs[i]);
526 m_intersections.push_back(intersection);
538 return m_intersections;
547 return m_intersections;
564 assert(m_initialized ==
true);
579 for(
int dim = 0; dim < 3; dim++)
581 T a_tmp = m_cpoints[dim][p-1]*0.5
583 + m_cpoints[dim][p+1]*0.5;
588 T b_tmp = - m_cpoints[dim][p-1]
594 T c_tmp = m_cpoints[dim][p-1]*0.5
595 + m_cpoints[dim][p]*0.5;
606 if(d >= -0.01 && d < 0.0) d = 0.0;
612 roots[0] = -b/(2.0*a);
614 if(roots[0] >= 0.0 && roots[0] <= 1.0)
621 r1 = (-b + sqrt(d))/(2.0*a);
622 r2 = (-b - sqrt(d))/(2.0*a);
624 if(r1 >= 0.0 && r1 <= 1.0)
629 if(r2 >= 0.0 && r2 <= 1.0)
640 std::vector<T> m_points[3];
642 std::vector<T> m_cpoints[3];
int m_axis
Which axis to use from plane matrix.
const IntersectionSet< T > & getConstIntersections() const
void setTransform(bool b)
void setSpline(const Spline3D< T > *spline)
std::vector< T > compute_control_points() const
bool m_initialized
True if m_cpoints is valid.
bool m_transform
Whether to transform when finding vector from plane matrix.
void evaluateSingle(T t, T point[3]) const
int findRoots(int p, Plane3D &plane, T roots[2]) const
static vector< Spline3D< T > > * build(vtkSmartPointer< vtkPolyData > data)
void findAllIntersections(const vector< MetaImage< inData_t > > &imgs)
void setMetaImage(const MetaImage< inData_t > *img)
void derivativeSingle(T t, T point[3]) const
void setPoints(vector< T > const &x, vector< T > const &y, vector< T > const &z)
T innerProduct(T const one[3], T const two[3])
void setValid(bool valid)
IntersectionSet< T > & getIntersections()
Intersection< T > findIntersection(const MetaImage< inData_t > *img) const
void setPoint(int idx, T const pt[3])
bool getTransform() const
void applyConvolution(vector< T > const &mask)
bool intersect(T &t, Plane3D &plane, T pointOnPlane[3]) const
void reportError(std::string errMsg)
double getCoefficient(const int i)
IntersectionSet< T > m_intersections
The intersections (as filled by findAllIntersections)
DoubleBoundingBox3D intersection(DoubleBoundingBox3D a, DoubleBoundingBox3D b)
double getDistance(double const pt[3]) const
void setParameterPosition(T t)