20#ifndef vtkBlockSortHelper_h
21#define vtkBlockSortHelper_h
67 double camWorldPos[4];
71 double camWorldFocalPoint[4];
73 camWorldFocalPoint[3] = 1.0;
77 InverseVolumeMatrix->DeepCopy(volMatrix);
78 InverseVolumeMatrix->Invert();
79 InverseVolumeMatrix->MultiplyPoint(camWorldPos, camWorldPos);
80 InverseVolumeMatrix->MultiplyPoint(camWorldFocalPoint, camWorldFocalPoint);
82 this->CameraPosition =
vtkVector3d(camWorldPos[0], camWorldPos[1], camWorldPos[2]);
83 this->CameraPosition = this->CameraPosition /
vtkVector3d(camWorldPos[3]);
85 vtkVector3d camFP(camWorldFocalPoint[0], camWorldFocalPoint[1], camWorldFocalPoint[2]);
105 template <
typename TT>
108 double abounds[6], bbounds[6];
109 vtkBlockSortHelper::GetBounds<TT>(first, abounds);
110 vtkBlockSortHelper::GetBounds<TT>(second, bbounds);
121 for (
int i = 0; i < 6; ++i)
123 int low = 2 * (i / 2);
124 bboundsP[i] = bbounds[i];
125 if (bboundsP[i] < abounds[low])
127 bboundsP[i] = abounds[low];
129 if (bboundsP[i] > abounds[low + 1])
131 bboundsP[i] = abounds[low + 1];
133 aboundsP[i] = abounds[i];
134 if (aboundsP[i] < bbounds[low])
136 aboundsP[i] = bbounds[low];
138 if (aboundsP[i] > bbounds[low + 1])
140 aboundsP[i] = bbounds[low + 1];
148 for (
int i = 0; i < 6; i += 2)
150 if (aboundsP[i] != aboundsP[i + 1])
152 dimSize[dims] = aboundsP[i + 1] - aboundsP[i];
157 degenAxes[degenDims] = i / 2;
167 if (dimSize[0] < dimSize[1])
169 if (dimSize[0] < dimSize[2])
180 if (dimSize[1] < dimSize[2])
194 double atobdir[3] = { bbounds[0] + bbounds[1] - abounds[0] - abounds[1],
195 bbounds[2] + bbounds[3] - abounds[2] - abounds[3],
196 bbounds[4] + bbounds[5] - abounds[4] - abounds[5] };
200 if (fabs(aboundsP[degenAxes[0] * 2] - bboundsP[degenAxes[0] * 2]) > 0.01 * atoblength)
207 if (this->CameraIsParallel)
214 vtkVector3d planePoint(0.25 * (aboundsP[0] + aboundsP[1] + bboundsP[0] + bboundsP[1]),
215 0.25 * (aboundsP[2] + aboundsP[3] + bboundsP[2] + bboundsP[3]),
216 0.25 * (aboundsP[4] + aboundsP[5] + bboundsP[4] + bboundsP[5]));
224 double plane[3] = { 0, 0, 0 };
225 plane[degenAxes[0]] = 1.0;
227 double dot = dir[0] * plane[0] + dir[1] * plane[1] + dir[2] * plane[2];
233 double side = plane[0] * atobdir[0] + plane[1] * atobdir[1] + plane[2] * atobdir[2];
234 return (dot * side < 0 ? 1 : -1);
242template <
class RandomIt>
247 bool Visited =
false;
248 std::vector<gnode<RandomIt>*> Closer;
251template <
class RandomIt>
252bool operator==(gnode<RandomIt>
const& lhs, gnode<RandomIt>
const& rhs)
254 return lhs.Value == rhs.Value && lhs.Closer == rhs.Closer;
257template <
class RandomIt>
258bool findCycle(gnode<RandomIt>& start, std::vector<gnode<RandomIt>>& graph,
259 std::vector<gnode<RandomIt>>& active, std::vector<gnode<RandomIt>>& loop)
267 active.push_back(start);
270 for (
auto& close : start.Closer)
278 for (
auto ait = active.begin(); ait != active.end(); ++ait)
280 if (ait->Value == close->Value)
282 loop.push_back(*ait);
287 if (findCycle(*close, graph, active, loop))
290 loop.push_back(*close);
295 active.erase(std::find(active.begin(), active.end(), start));
296 start.Visited =
true;
301template <
class RandomIt,
typename T>
308 std::vector<typename RandomIt::value_type> working;
309 std::vector<typename RandomIt::value_type> result;
310 working.assign(bitr, eitr);
311 size_t numNodes = working.size();
315 for (
auto it = working.begin(); it != working.end(); ++it)
319 for (; it2 != working.end(); ++it2)
323 if (comp1 * comp2 > 0)
332 std::vector<gnode<RandomIt>> graph;
333 for (
auto it = working.begin(); it != working.end(); ++it)
335 gnode<RandomIt> anode;
337 graph.push_back(anode);
339 for (
auto& git : graph)
341 for (
auto& next : graph)
345 git.Closer.push_back(&next);
351 std::vector<gnode<RandomIt>> active;
352 std::vector<gnode<RandomIt>> loop;
353 for (
auto& gval : graph)
356 if (findCycle(gval, graph, active, loop))
360 vtkGenericWarningMacro(
"found a loop cam dir: " << dir[0] <<
" " << dir[1] <<
" " << dir[2]);
361 for (
auto& lval : loop)
365 vtkGenericWarningMacro(<< bnds[0] <<
" " << bnds[1] <<
" " << bnds[2] <<
" " << bnds[3]
366 <<
" " << bnds[4] <<
" " << bnds[5]);
373 for (
auto it = working.begin(); it != working.end();)
375 auto it2 = working.begin();
376 for (; it2 != working.end(); ++it2)
386 if (it2 == working.end())
389 result.push_back(*it);
391 it = working.begin();
399 if (result.size() != numNodes)
401 vtkGenericWarningMacro(
"sorting failed");
405 std::reverse_copy(result.begin(), result.end(), start);
a virtual camera for 3D rendering
virtual double * GetFocalPoint()
Set/Get the focal of the camera in world coordinates.
virtual double * GetPosition()
Set/Get the position of the camera in world coordinates.
virtual vtkTypeBool GetParallelProjection()
Set/Get the value of the ParallelProjection instance variable.
abstract class to specify dataset behavior
double * GetBounds()
Return a pointer to the geometry bounding box in the form (xmin,xmax, ymin,ymax, zmin,...
static float Normalize(float v[3])
Normalize (in place) a 3-vector.
represent and manipulate 4x4 transformation matrices
Allocate and hold a VTK object.
abstract specification for renderers
vtkCamera * GetActiveCamera()
Get the current camera.
double Normalize()
Normalize the vector in place.
Collection of comparison functions for std::sort.
void Sort(RandomIt bitr, RandomIt eitr, BackToFront< T > &me)
void GetBounds(T a, double bds[6])
operator() for back-to-front sorting.
int CompareOrderWithUncertainty(TT &first, TT &second)
int CompareBoundsOrderWithUncertainty(const double abounds[6], const double bbounds[6])
BackToFront(vtkRenderer *ren, vtkMatrix4x4 *volMatrix)
BackToFront(const vtkVector3d &camPos, const vtkVector3d &viewdirection, bool is_parallel)
vtkVector3d CameraPosition
vtkVector3d CameraViewDirection
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)