17 #include <vtkAbstractPropPicker.h> 19 #include <vtkAreaPicker.h> 20 #include <vtkAssemblyPath.h> 21 #include <vtkObjectFactory.h> 22 #include <vtkRenderWindow.h> 23 #include <vtkRenderWindowInteractor.h> 24 #include <vtkRenderer.h> 25 #include <vtkUnsignedCharArray.h> 26 #include <vtkVectorOperators.h> 27 #include <vtkCommand.h> 32 #define VTKISRBP_ORIENT 0 33 #define VTKISRBP_SELECT 1 43 this->points.pop_back();
46 void AddPoint(
const vtkVector2i& point) { this->points.push_back(point); }
51 vtkVector2i
GetPoint(vtkIdType index)
const {
return this->points[index]; }
55 void Clear() { this->points.clear(); }
58 const vtkVector2i& StartPos,
const vtkVector2i& EndPos,
unsigned char* pixels,
int* size)
60 int x1 = StartPos.GetX(), x2 = EndPos.GetX();
61 int y1 = StartPos.GetY(), y2 = EndPos.GetY();
65 double length = sqrt(x * x + y * y);
70 double addx = x / length;
71 double addy = y / length;
76 for (
double i = 0; i < length; i += 1)
80 pixels[3 * (row * size[0] + col)] = 255 ^ pixels[3 * (row * size[0] + col)];
81 pixels[3 * (row * size[0] + col) + 1] = 255 ^ pixels[3 * (row * size[0] + col) + 1];
82 pixels[3 * (row * size[0] + col) + 2] = 255 ^ pixels[3 * (row * size[0] + col) + 2];
98 this->
PixelArray = vtkUnsignedCharArray::New();
123 switch (this->Interactor->GetKeyCode())
140 vtkRenderWindowInteractor* rwi = this->Interactor;
141 int* eventPos = rwi->GetEventPosition();
142 this->FindPokedRenderer(eventPos[0], eventPos[1]);
151 this->Superclass::OnChar();
162 this->Superclass::OnLeftButtonDown();
166 if (!this->Interactor)
184 vtkRenderWindow* renWin = this->Interactor->GetRenderWindow();
186 this->
StartPosition[0] = this->Interactor->GetEventPosition()[0];
187 this->
StartPosition[1] = this->Interactor->GetEventPosition()[1];
193 int* size = renWin->GetSize();
194 this->
PixelArray->SetNumberOfTuples(size[0] * size[1]);
196 renWin->GetPixelData(0, 0, size[0] - 1, size[1] - 1, 1, this->
PixelArray);
199 this->InvokeEvent(vtkCommand::StartInteractionEvent);
211 this->Superclass::OnMouseMove();
215 if (!this->Interactor || !this->
Moving)
220 this->
EndPosition[0] = this->Interactor->GetEventPosition()[0];
221 this->
EndPosition[1] = this->Interactor->GetEventPosition()[1];
222 int* size = this->Interactor->GetRenderWindow()->GetSize();
242 if ((lastPoint - newPoint).SquaredNorm() > 100)
262 this->Superclass::OnLeftButtonUp();
266 if (!this->Interactor || !this->
Moving)
274 vtkVector2i newPoint(this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]);
296 inline bool compareX(vtkVector2i i, vtkVector2i j) {
return (i[0] < j[0]);};
297 inline bool compareY(vtkVector2i i, vtkVector2i j) {
return (i[1] < j[1]);};
304 int* size = this->Interactor->GetRenderWindow()->GetSize();
307 min[0] = std::min_element(polygonPoints.begin(), polygonPoints.end(),
compareX)->GetX();
308 min[1] = std::min_element(polygonPoints.begin(), polygonPoints.end(),
compareY)->GetY();
310 max[0] = std::max_element(polygonPoints.begin(), polygonPoints.end(),
compareX)->GetX();
311 max[1] = std::max_element(polygonPoints.begin(), polygonPoints.end(),
compareY)->GetY();
316 rbcenter[0] = (min[0] + max[0]) / 2.0;
317 rbcenter[1] = (min[1] + max[1]) / 2.0;
320 if (this->State == VTKIS_NONE)
323 vtkRenderWindowInteractor* rwi = this->Interactor;
325 vtkAssemblyPath* path =
nullptr;
326 rwi->StartPickCallback();
327 vtkAbstractPropPicker* picker = vtkAbstractPropPicker::SafeDownCast(rwi->GetPicker());
328 if (picker !=
nullptr)
330 vtkAreaPicker* areaPicker = vtkAreaPicker::SafeDownCast(picker);
331 if (areaPicker !=
nullptr)
333 areaPicker->AreaPick(min[0], min[1], max[0], max[1], this->CurrentRenderer);
337 picker->Pick(rbcenter[0], rbcenter[1], 0.0, this->CurrentRenderer);
339 path = picker->GetPath();
343 this->HighlightProp(
nullptr);
344 this->PropPicked = 0;
350 this->PropPicked = 1;
352 rwi->EndPickCallback();
355 this->Interactor->Render();
361 vtkNew<vtkUnsignedCharArray> tmpPixelArray;
363 unsigned char* pixels = tmpPixelArray->GetPointer(0);
364 int* size = this->Interactor->GetRenderWindow()->GetSize();
384 this->Interactor->GetRenderWindow()->SetPixelData(0, 0, size[0] - 1, size[1] - 1, pixels, 0);
385 this->Interactor->GetRenderWindow()->Frame();
391 this->Superclass::PrintSelf(os, indent);
396 std::cout <<
"lasso" << std::endl;
402 std::cout <<
"no lasso" << std::endl;
421 std::cout <<
"did this " << std::endl;
bool compareY(vtkVector2i i, vtkVector2i j)
void OnLeftButtonUp() override
void PrintSelf(ostream &os, vtkIndent indent) override
LVRInteractorStylePolygonPick()
void AddPoint(const vtkVector2i &point)
void OnMouseMove() override
std::vector< vtkVector2i > points
vtkUnsignedCharArray * PixelArray
~LVRInteractorStylePolygonPick() override
void OnLeftButtonDown() override
vtkIdType GetNumberOfPoints() const
Like TrackBallCamera, but this can pick props underneath a rubber band selection rectangle.
virtual void DrawPolygon()
vtkVector2i GetPoint(vtkIdType index) const
void AddPoint(int x, int y)
void DrawPixels(const vtkVector2i &StartPos, const vtkVector2i &EndPos, unsigned char *pixels, int *size)
vtkStandardNewMacro(LVRInteractorStylePolygonPick)
bool compareX(vtkVector2i i, vtkVector2i j)
std::vector< vtkVector2i > GetPolygonPoints()
void OnKeyDown() override