36 #include "vtkImageData.h"
37 #include <vtkPointData.h>
38 #include <vtkUnsignedCharArray.h>
39 #include <vtkPolyData.h>
40 #include <vtkCellArray.h>
41 #include <vtkFloatArray.h>
42 #include <vtkPolyLine.h>
43 #include <vtkClipPolyData.h>
46 #include <vtkPlanes.h>
47 #include <vtkCutter.h>
48 #include <vtkAppendPolyData.h>
65 mPolyData = vtkPolyDataPtr::New();
82 mData(data), m_vMu(uMv.
inv())
93 return this->insideClipRect(p_v) && this->insideSector(p_v);
102 bool insideClipRect(
const Vector3D& p_v)
const
112 bool insideSector(
const Vector3D& p_v)
const
118 double angle = atan2(d[1], d[0]);
123 if (fabs(angle) > mData.
getWidth() / 2.0)
133 if (fabs(d[0]) > mData.
getWidth() / 2.0)
143 ProbeDefinition mData;
146 DoubleBoundingBox3D mClipRect_v;
161 int* dim(retval->GetDimensions());
162 unsigned char* dataPtr =
static_cast<unsigned char*
> (retval->GetScalarPointer());
163 for (
int x = 0; x < dim[0]; x++)
164 for (
int y = 0; y < dim[1]; y++)
166 dataPtr[x + y * dim[0]] = checkInside(x, y) ? 1 : 0;
180 std::cout <<
"zero = tMu * mOrigin_u, zero: " << tMu.coord(
mData.
getOrigin_u()) <<
", mOrigin_u: "
184 std::cout <<
"e_z = tMu * -e_y " << tMu.vector(-e_y) << std::endl;
187 std::cout <<
"e_y = tMu * -e_x " << tMu.vector(-e_x) << std::endl;
190 std::cout <<
"tMu * e_x = <0,-1,0>" << tMu.vector(e_x) << std::endl;
192 std::cout <<
"tMu * e_y = <0,0,-1> " << tMu.vector(e_y) << std::endl;
224 bool ProbeSector::clipRectIntersectsSector()
const
230 bool outside = ( (c[0] < s[0]) ||
similar(c[0],s[0], tol) )
231 && ( (s[1] < c[1]) ||
similar(s[1],c[1], tol) )
232 && ( (c[2] < s[2]) ||
similar(c[2],s[2], tol) )
233 && ( (s[3] < c[3]) ||
similar(s[3],c[3], tol) );
244 output->SetPoints(mPolyData->GetPoints());
245 output->SetLines(mPolyData->GetLines());
249 retval->AddInputData(output);
251 if (this->clipRectIntersectsSector())
252 retval->AddInputData(this->getClipRectPolyData());
255 return retval->GetOutput();
265 output->SetPoints(mPolyData->GetPoints());
266 output->SetLines(mPolyData->GetLines());
274 return this->getClipRectPolyData();
284 sides->InsertNextCell(5, cells);
287 points->InsertNextPoint(bb.corner(0, 0, 0).begin());
288 points->InsertNextPoint(bb.corner(1, 0, 0).begin());
289 points->InsertNextPoint(bb.corner(1, 1, 0).begin());
290 points->InsertNextPoint(bb.corner(0, 1, 0).begin());
293 polydata->SetPoints(points);
294 polydata->SetLines(sides);
309 sides->InsertNextCell(4, cells);
315 Vector3D left = o_u +
Vector3D(-length/3, 0, 0);
316 Vector3D right = o_u +
Vector3D(length/3, 0, 0);
318 points->InsertNextPoint(o_u.begin());
319 points->InsertNextPoint(tip.begin());
320 points->InsertNextPoint(left.begin());
321 points->InsertNextPoint(right.begin());
324 polydata->SetPoints(points);
325 polydata->SetLines(sides);
334 mPolyData = vtkPolyDataPtr::New();
342 newTCoords->SetNumberOfComponents(2);
349 Transform3D texMu =
createTransformNormalize(
DoubleBoundingBox3D(0, bounds[0], 0, bounds[1], 0, 1),
DoubleBoundingBox3D(0, 1, 0, 1, 0, 1));
374 points->InsertNextPoint(uMl.coord(cl).begin());
375 points->InsertNextPoint(uMl.coord(cr).begin());
376 points->InsertNextPoint(uMl.coord(pr).begin());
377 points->InsertNextPoint(uMl.coord(pl).begin());
379 newTCoords->Allocate(4);
380 newTCoords->InsertNextTuple(texMl.coord(cl).begin());
381 newTCoords->InsertNextTuple(texMl.coord(cr).begin());
382 newTCoords->InsertNextTuple(texMl.coord(pr).begin());
383 newTCoords->InsertNextTuple(texMl.coord(pl).begin());
385 vtkIdType cells[5] = { 0, 1, 2, 3, 0 };
386 sides->InsertNextCell(5, cells);
387 polys->InsertNextCell(5, cells);
388 vtkIdType s_cells[5] = { 0, 3, 1, 2 };
389 strips->InsertNextCell(4, s_cells);
400 int N = 2 * (arcRes + 1);
403 newTCoords->Allocate(2 * N);
405 for (
int i = 0; i <= arcRes; i++)
407 double theta = startAngle + i * angleIncrement;
417 newTCoords->InsertNextTuple(texMl.coord(startTheta).begin());
418 points->InsertNextPoint(uMl.coord(startTheta).begin());
421 for (
int i = 0; i <= arcRes; i++)
423 double theta = stopAngle - i * angleIncrement;
432 newTCoords->InsertNextTuple(texMl.coord(endTheta).begin());
433 points->InsertNextPoint(uMl.coord(endTheta).begin());
436 sides->InsertNextCell(N + 1);
437 for (
int i = 0; i < N; i++)
438 sides->InsertCellPoint(i);
439 sides->InsertCellPoint(0);
441 polys->InsertNextCell(N + 1);
442 for (
int i = 0; i < arcRes * 2 + 2; i++)
443 polys->InsertCellPoint(i);
444 polys->InsertCellPoint(0);
446 strips->InsertNextCell(N);
447 for (
int i = 0; i <= arcRes; ++i)
449 strips->InsertCellPoint(i);
450 strips->InsertCellPoint(N - 1 - i);
455 polydata->SetPoints(points);
456 polydata->SetStrips(strips);
457 polydata->GetPointData()->SetTCoords(newTCoords);
458 polydata->SetLines(sides);
459 mPolyData = polydata;
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
Transform3D createTransformRotateY(const double angle)
vtkSmartPointer< class vtkPlanes > vtkPlanesPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkPolyDataPtr getSector()
get a polydata representation of the us sector
vtkSmartPointer< class vtkCellArray > vtkCellArrayPtr
double getCenterOffset() const
US beam is emitted straight forward.
Vector3D unitVector(double thetaXY, double thetaZ)
compute a unit vector given angles xy in the xy plane and z meaning the elevation from the xy plane...
vtkSmartPointer< class vtkAppendPolyData > vtkAppendPolyDataPtr
vtkSmartPointer< class vtkFloatArray > vtkFloatArrayPtr
vtkPolyDataPtr getSectorLinesOnly()
get a polydata representation of the us sector
vtkSmartPointer< class vtkBox > vtkBoxPtr
double getDepthStart() const
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
Transform3D createTransformNormalize(const DoubleBoundingBox3D &in, const DoubleBoundingBox3D &out)
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
double getDepthEnd() const
Transform3D createTransformIJC(const Vector3D &ivec, const Vector3D &jvec, const Vector3D ¢er)
Transform3D get_uMv() const
get transform from inverted image space v (origin in ul corner) to image space u. ...
InsideMaskFunctor(ProbeDefinition data, Transform3D uMv)
US beam is emitted radially in a flat cone.
vtkPolyDataPtr getSectorSectorOnlyLinesOnly()
get a polydata representation of the us sector
double constrainValue(double val, double min, double max)
DoubleBoundingBox3D getClipRect_u() const
sector clipping rect in image space u. (lower-left corner origin)
Transform3D createTransformTranslate(const Vector3D &translation)
vtkPolyDataPtr getClipRectLinesOnly()
get a polydata representation of the us clip rect
Transform3D get_tMu() const
get transform from image space u to probe tool space t.
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
vtkImageDataPtr generateVtkImageData(Eigen::Array3i dim, Vector3D spacing, const unsigned char initValue, int components)
vtkSmartPointer< class vtkCutter > vtkCutterPtr
Vector3D getOrigin_u() const
probe origin in image space u. (lower-left corner origin)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition of characteristics for an Ultrasound Probe Sector.
Vector3D multiply_elems(const Vector3D &a, const Vector3D &b)
perform element-wise multiplication of a and b.
Vector3D getSpacing() const
bool operator()(int x, int y) const
vtkImageDataPtr getMask()
RealScalar length() const
Transform3D createTransformRotateX(const double angle)
vtkPolyDataPtr getOriginPolyData()
get a polydata representation of the origin
vtkSmartPointer< class vtkPlane > vtkPlanePtr
vtkSmartPointer< class vtkPoints > vtkPointsPtr
bool contains(const Vector3D &p) const
void setData(ProbeDefinition data)