25 #ifndef vtkStreamingPriorityQueue_h 26 #define vtkStreamingPriorityQueue_h 28 #include "vtkBoundingBox.h" 38 double vtkComputeScreenCoverage(
const double planes[24],
const double bounds[6],
double& distance,
39 double& centeredness,
double& itemCoverage)
46 if (!vtkMath::AreBoundsInitialized(const_cast<double*>(bounds)))
50 double screen_bounds[4];
53 center[0] = (bounds[0] + bounds[1]) / 2.0;
54 center[1] = (bounds[2] + bounds[3]) / 2.0;
55 center[2] = (bounds[4] + bounds[5]) / 2.0;
56 double radius = 0.5 * sqrt((bounds[1] - bounds[0]) * (bounds[1] - bounds[0]) +
57 (bounds[3] - bounds[2]) * (bounds[3] - bounds[2]) +
58 (bounds[5] - bounds[4]) * (bounds[5] - bounds[4]));
59 for (
int i = 0; i < 6; i++)
62 double d = planes[i * 4 + 0] * center[0] + planes[i * 4 + 1] * center[1] +
63 planes[i * 4 + 2] * center[2] + planes[i * 4 + 3];
76 screen_bounds[i] = d - radius;
89 double full_w = screen_bounds[0] + screen_bounds[1] + 2.0 * radius;
90 double full_h = screen_bounds[2] + screen_bounds[3] + 2.0 * radius;
96 (screen_bounds[0] + radius) * (screen_bounds[1] + radius) / (full_w * full_w / 4.0);
98 (screen_bounds[2] + radius) * (screen_bounds[3] + radius) / (full_h * full_h / 4.0);
102 if (measure_w < 0.01)
106 if (measure_h < 0.01)
110 centeredness = measure_w * measure_h;
112 double w = 2 * radius;
113 double h = 2 * radius;
114 if (screen_bounds[0] < 0.0)
116 w += screen_bounds[0];
118 if (screen_bounds[1] < 0.0)
120 w += screen_bounds[1];
122 if (screen_bounds[2] < 0.0)
124 h += screen_bounds[2];
126 if (screen_bounds[3] < 0.0)
128 h += screen_bounds[3];
130 itemCoverage = h * w / (4 * radius * radius);
139 double part_w = full_w;
140 if (screen_bounds[0] > 0.0)
142 part_w -= screen_bounds[0];
144 if (screen_bounds[1] > 0.0)
146 part_w -= screen_bounds[1];
150 double part_h = full_h;
151 if (screen_bounds[2] > 0.0)
153 part_h -= screen_bounds[2];
155 if (screen_bounds[3] > 0.0)
157 part_h -= screen_bounds[3];
161 if ((full_w * full_h) != 0.0)
163 return (part_w * part_h) / (full_w * full_h);
209 template <
typename Comparator = vtkStreamingPriorityQueueItemComparator>
211 std::vector<vtkStreamingPriorityQueueItem>, Comparator>
220 bool clamp_bounds_initialized =
221 (vtkMath::AreBoundsInitialized(const_cast<double*>(clamp_bounds)) != 0);
222 vtkBoundingBox clampBox(const_cast<double*>(clamp_bounds));
226 std::swap(current_queue, *
this);
228 for (; !current_queue.empty(); current_queue.pop())
231 if (!item.
Bounds.IsValid())
236 double block_bounds[6];
237 item.
Bounds.GetBounds(block_bounds);
239 if (clamp_bounds_initialized)
241 if (!clampBox.ContainsPoint(block_bounds[0], block_bounds[2], block_bounds[4]) &&
242 !clampBox.ContainsPoint(block_bounds[1], block_bounds[3], block_bounds[5]))
250 double distance, centeredness, itemCoverage;
252 vtkComputeScreenCoverage(view_planes, block_bounds, distance, centeredness, itemCoverage);
262 item.
Priority = coverage * coverage * centeredness / (1 + refinement2 + distance);
void UpdatePriorities(const double view_planes[24], const double clamp_bounds[6])
Updates the priorities of items in the queue.
vtkStreamingPriorityQueueItem()
bool operator()(const vtkStreamingPriorityQueueItem &me, const vtkStreamingPriorityQueueItem &other) const
provides a datastructure for building priority queues.