1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/*=========================================================================
Program: ParaView
Module: $RCSfile$
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkAMRStreamingPriorityQueue.h"
#include "vtkAMRInformation.h"
#include "vtkBoundingBox.h"
#include "vtkMath.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingPriorityQueue.h"
#include <assert.h>
#include <queue>
#include <vector>
class vtkAMRStreamingPriorityQueue::vtkInternals
{
public:
vtkStreamingPriorityQueue<> PriorityQueue;
vtkSmartPointer<vtkAMRInformation> AMRMetadata;
};
vtkStandardNewMacro(vtkAMRStreamingPriorityQueue);
vtkCxxSetObjectMacro(vtkAMRStreamingPriorityQueue, Controller, vtkMultiProcessController);
//----------------------------------------------------------------------------
vtkAMRStreamingPriorityQueue::vtkAMRStreamingPriorityQueue()
{
this->Internals = new vtkInternals();
this->Controller = 0;
this->SetController(vtkMultiProcessController::GetGlobalController());
}
//----------------------------------------------------------------------------
vtkAMRStreamingPriorityQueue::~vtkAMRStreamingPriorityQueue()
{
delete this->Internals;
this->Internals = 0;
this->SetController(0);
}
//----------------------------------------------------------------------------
void vtkAMRStreamingPriorityQueue::Initialize(vtkAMRInformation* amr)
{
delete this->Internals;
this->Internals = new vtkInternals();
this->Internals->AMRMetadata = amr;
for (unsigned int cc=0; cc < amr->GetTotalNumberOfBlocks(); cc++)
{
vtkStreamingPriorityQueueItem item;
item.Identifier = cc;
item.Priority = (amr->GetTotalNumberOfBlocks() - cc);
unsigned int level=0, index=0;
this->Internals->AMRMetadata->ComputeIndexPair(
item.Identifier, level, index);
item.Refinement = static_cast<double>(level);
double block_bounds[6];
this->Internals->AMRMetadata->GetBounds(level, index, block_bounds);
item.Bounds.SetBounds(block_bounds);
// default priority is to prefer lower levels. Thus even without
// view-planes we have reasonable priority.
this->Internals->PriorityQueue.push(item);
}
}
//----------------------------------------------------------------------------
void vtkAMRStreamingPriorityQueue::Reinitialize()
{
if (this->Internals->AMRMetadata)
{
vtkSmartPointer<vtkAMRInformation> info = this->Internals->AMRMetadata;
this->Initialize(info);
}
}
//----------------------------------------------------------------------------
bool vtkAMRStreamingPriorityQueue::IsEmpty()
{
return this->Internals->PriorityQueue.empty();
}
//----------------------------------------------------------------------------
unsigned int vtkAMRStreamingPriorityQueue::Pop()
{
if (this->IsEmpty())
{
vtkErrorMacro("Queue is empty!");
return 0;
}
int num_procs = this->Controller? this->Controller->GetNumberOfProcesses() : 1;
int myid = this->Controller? this->Controller->GetLocalProcessId() : 0;
assert(myid < num_procs);
std::vector<vtkStreamingPriorityQueueItem> items;
items.resize(num_procs);
for (int cc=0; cc < num_procs && !this->Internals->PriorityQueue.empty(); cc++)
{
items[cc] = this->Internals->PriorityQueue.top();
this->Internals->PriorityQueue.pop();
}
// at the end, when the queue empties out in the middle of a pop, right now,
// all other processes are simply going to ask for block 0 (set in
// initialization of vtkStreamingPriorityQueueItem). We can change that, if needed.
return items[myid].Identifier;
}
//----------------------------------------------------------------------------
void vtkAMRStreamingPriorityQueue::Update(const double view_planes[24])
{
double clamp_bounds[6];
vtkMath::UninitializeBounds(clamp_bounds);
this->Update(view_planes, clamp_bounds);
}
//----------------------------------------------------------------------------
void vtkAMRStreamingPriorityQueue::Update(const double view_planes[24],
const double clamp_bounds[6])
{
if (!this->Internals->AMRMetadata)
{
return;
}
this->Internals->PriorityQueue.UpdatePriorities(view_planes, clamp_bounds);
}
//----------------------------------------------------------------------------
void vtkAMRStreamingPriorityQueue::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Controller: " << this->Controller << endl;
}
|