23 #include <vtkActorCollection.h>
24 #include <vtkDataObject.h>
25 #include <vtkMapper.h>
26 #include <vtkObjectFactory.h>
28 #include <vtkRenderWindow.h>
29 #include <vtkRenderer.h>
30 #include <vtkSelection.h>
34 #ifdef cvHardwareSelectorDEBUG
35 #include <vtkImageImport.h>
37 #include <vtkPNMWriter.h>
49 this->SetUseProcessIdFromData(
true);
63 if (pass == PROCESS_PASS && this->Iteration == 0) {
67 return this->Superclass::PassRequired(pass);
76 if (!this->Renderer) {
78 "[cvHardwareSelector::PrepareSelect] No renderer set!");
82 int*
size = this->Renderer->GetSize();
83 int*
origin = this->Renderer->GetOrigin();
88 if (this->CaptureBuffers() ==
false) {
90 "[cvHardwareSelector::PrepareSelect] CaptureBuffers "
104 CVLog::Error(
"[cvHardwareSelector::Select] PrepareSelect failed!");
109 this->GenerateSelection(region[0], region[1], region[2], region[3]);
118 bool noNodes = (sel->GetNumberOfNodes() == 0);
119 bool isPointSelection =
120 (this->FieldAssociation == vtkDataObject::FIELD_ASSOCIATION_POINTS);
121 bool isSingleClick = (region[0] == region[2] && region[1] == region[3]);
124 if (noNodes && isPointSelection && isSingleClick && hasRadius) {
126 pos[0] =
static_cast<unsigned int>(region[0]);
127 pos[1] =
static_cast<unsigned int>(region[1]);
129 unsigned int out_pos[2];
130 vtkHardwareSelector::PixelInformation info = this->GetPixelInformation(
135 return this->GenerateSelection(out_pos[0], out_pos[1], out_pos[0],
149 return this->GeneratePolygonSelection(polygonPoints,
count);
166 this->PropMap[prop] = id;
175 auto iter = this->PropMap.find(prop);
176 if (iter != this->PropMap.end()) {
191 this->Superclass::PrintSelf(os, indent);
193 os << indent <<
"UniqueId: " << this->
UniqueId <<
"\n";
194 os << indent <<
"PropMap size: " << this->PropMap.size() <<
"\n";
200 this->Superclass::BeginSelection();
211 this->Superclass::BeginRenderProp(rw);
217 this->Superclass::SavePixelBuffer(passNo);
219 #ifdef cvHardwareSelectorDEBUG
220 vtkNew<vtkImageImport> ii;
221 ii->SetImportVoidPointer(this->PixBuffer[passNo], 1);
222 ii->SetDataScalarTypeToUnsignedChar();
223 ii->SetNumberOfScalarComponents(3);
224 ii->SetDataExtent(this->Area[0], this->Area[2], this->Area[1],
225 this->Area[3], 0, 0);
226 ii->SetWholeExtent(this->Area[0], this->Area[2], this->Area[1],
227 this->Area[3], 0, 0);
229 std::ostringstream fname;
230 fname <<
"/tmp/cv-buffer-pass-" << passNo <<
".pnm";
231 vtkNew<vtkPNMWriter> pw;
232 pw->SetInputConnection(ii->GetOutputPort());
233 pw->SetFileName(fname.str().c_str());
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Hardware selector with ParaView-style buffer caching.
int AssignUniqueId(vtkProp *prop)
Assign a unique ID to a prop.
int GetPropID(int idx, vtkProp *prop) override
Return a unique ID for the prop.
int UniqueId
Counter for unique prop IDs.
~cvHardwareSelector() override
void EndSelection() override
End selection - clears selector from renderer.
void PrintSelf(ostream &os, vtkIndent indent) override
void BeginRenderProp(vtkRenderWindow *rw) override
Begin render prop (sets ProcessID)
virtual bool NeedToRenderForSelection()
Check if next Select() will need to render.
virtual vtkSelection * Select(int region[4])
Perform selection over the specified region.
vtkTimeStamp CaptureTime
Time when buffers were last captured.
bool PassRequired(int pass) override
Check if a pass is required.
void SavePixelBuffer(int passNo) override
Save pixel buffer (with optional debug output)
unsigned int PointPickingRadius
Point picking radius in pixels (default: 10)
vtkSelection * PolygonSelect(int *polygonPoints, vtkIdType count)
Perform polygon selection.
void BeginSelection() override
Begin selection - sets selector on renderer.
bool PrepareSelect()
Prepare for selection.
vtkStandardNewMacro(cvHardwareSelector)