8#ifndef vtkBlockSortHelper_h
9#define vtkBlockSortHelper_h
22VTK_ABI_NAMESPACE_BEGIN
55 double camWorldPos[4];
59 double camWorldFocalPoint[4];
61 camWorldFocalPoint[3] = 1.0;
65 InverseVolumeMatrix->DeepCopy(volMatrix);
66 InverseVolumeMatrix->Invert();
67 InverseVolumeMatrix->MultiplyPoint(camWorldPos, camWorldPos);
68 InverseVolumeMatrix->MultiplyPoint(camWorldFocalPoint, camWorldFocalPoint);
70 this->CameraPosition =
vtkVector3d(camWorldPos[0], camWorldPos[1], camWorldPos[2]);
71 this->CameraPosition = this->CameraPosition /
vtkVector3d(camWorldPos[3]);
73 vtkVector3d camFP(camWorldFocalPoint[0], camWorldFocalPoint[1], camWorldFocalPoint[2]);
93 template <
typename TT>
96 double abounds[6], bbounds[6];
97 vtkBlockSortHelper::GetBounds<TT>(first, abounds);
98 vtkBlockSortHelper::GetBounds<TT>(second, bbounds);
109 for (
int i = 0; i < 6; ++i)
111 int low = 2 * (i / 2);
112 bboundsP[i] = bbounds[i];
113 bboundsP[i] = std::max(bboundsP[i], abounds[low]);
114 bboundsP[i] = std::min(bboundsP[i], abounds[low + 1]);
115 aboundsP[i] = abounds[i];
116 aboundsP[i] = std::max(aboundsP[i], bbounds[low]);
117 aboundsP[i] = std::min(aboundsP[i], bbounds[low + 1]);
124 for (
int i = 0; i < 6; i += 2)
126 if (aboundsP[i] != aboundsP[i + 1])
128 dimSize[dims] = aboundsP[i + 1] - aboundsP[i];
133 degenAxes[degenDims] = i / 2;
143 if (dimSize[0] < dimSize[1])
145 if (dimSize[0] < dimSize[2])
156 if (dimSize[1] < dimSize[2])
170 double atobdir[3] = { bbounds[0] + bbounds[1] - abounds[0] - abounds[1],
171 bbounds[2] + bbounds[3] - abounds[2] - abounds[3],
172 bbounds[4] + bbounds[5] - abounds[4] - abounds[5] };
176 if (fabs(aboundsP[degenAxes[0] * 2] - bboundsP[degenAxes[0] * 2]) > 0.01 * atoblength)
183 if (this->CameraIsParallel)
190 vtkVector3d planePoint(0.25 * (aboundsP[0] + aboundsP[1] + bboundsP[0] + bboundsP[1]),
191 0.25 * (aboundsP[2] + aboundsP[3] + bboundsP[2] + bboundsP[3]),
192 0.25 * (aboundsP[4] + aboundsP[5] + bboundsP[4] + bboundsP[5]));
200 double plane[3] = { 0, 0, 0 };
201 plane[degenAxes[0]] = 1.0;
203 double dot = dir[0] * plane[0] + dir[1] * plane[1] + dir[2] * plane[2];
209 double side = plane[0] * atobdir[0] + plane[1] * atobdir[1] + plane[2] * atobdir[2];
210 return (dot * side < 0 ? 1 : -1);
218template <
class RandomIt>
223 bool Visited =
false;
224 std::vector<gnode<RandomIt>*> Closer;
227template <
class RandomIt>
228bool operator==(gnode<RandomIt>
const& lhs, gnode<RandomIt>
const& rhs)
230 return lhs.Value == rhs.Value && lhs.Closer == rhs.Closer;
233template <
class RandomIt>
234bool findCycle(gnode<RandomIt>& start, std::vector<gnode<RandomIt>>& graph,
235 std::vector<gnode<RandomIt>>& active, std::vector<gnode<RandomIt>>& loop)
243 active.push_back(start);
246 for (
auto& close : start.Closer)
254 for (
auto ait = active.begin(); ait != active.end(); ++ait)
256 if (ait->Value == close->Value)
258 loop.push_back(*ait);
263 if (findCycle(*close, graph, active, loop))
266 loop.push_back(*close);
271 active.erase(std::find(active.begin(), active.end(), start));
272 start.Visited =
true;
277template <
class RandomIt,
typename T>
284 std::vector<typename RandomIt::value_type> working;
285 std::vector<typename RandomIt::value_type> result;
286 working.assign(bitr, eitr);
287 size_t numNodes = working.size();
291 for (
auto it = working.begin(); it != working.end(); ++it)
295 for (; it2 != working.end(); ++it2)
299 if (comp1 * comp2 > 0)
308 std::vector<gnode<RandomIt>> graph;
309 for (
auto it = working.begin(); it != working.end(); ++it)
311 gnode<RandomIt> anode;
313 graph.push_back(anode);
315 for (
auto& git : graph)
317 for (
auto& next : graph)
321 git.Closer.push_back(&next);
327 std::vector<gnode<RandomIt>> active;
328 std::vector<gnode<RandomIt>> loop;
329 for (
auto& gval : graph)
332 if (findCycle(gval, graph, active, loop))
336 vtkGenericWarningMacro(
"found a loop cam dir: " << dir[0] <<
" " << dir[1] <<
" " << dir[2]);
337 for (
auto& lval : loop)
341 vtkGenericWarningMacro(<< bnds[0] <<
" " << bnds[1] <<
" " << bnds[2] <<
" " << bnds[3]
342 <<
" " << bnds[4] <<
" " << bnds[5]);
349 for (
auto it = working.begin(); it != working.end();)
351 auto it2 = working.begin();
352 for (; it2 != working.end(); ++it2)
362 if (it2 == working.end())
365 result.push_back(*it);
367 it = working.begin();
375 if (result.size() != numNodes)
377 vtkGenericWarningMacro(
"sorting failed");
381 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
bool VTKCOMMONCORE_EXPORT operator==(const std::string &a, const vtkStringToken &b)