2 #include <vtkCoordinate.h> 3 #include <QInputDialog> 19 colors.push_back({255, 255, 102});
20 colors.push_back({127, 0, 255});
21 colors.push_back({255,0,255});
22 colors.push_back({0,255 ,0 });
23 colors.push_back({255, 0, 127});
24 colors.push_back({0,128 ,255});
25 colors.push_back({0,204 ,102});
26 colors.push_back({153, 204, 255});
27 colors.push_back({153, 255, 204});
28 colors.push_back({255, 153, 153});
29 colors.push_back({153, 76, 0});
30 colors.push_back({0, 255, 128});
46 bool isInside(std::vector<vtkVector2i> polygon,
int& pX,
int& pY)
48 int n = polygon.size();
49 if (n < 3)
return false;
52 for(i = 0, j = n -1; i < n ; j = i++)
54 auto& vert = polygon[j];
55 auto& vert_next = polygon[i];
57 if ( ((vert_next.GetY()>pY) != (vert.GetY()>pY)) &&
58 (pX < (vert.GetX()-vert_next.GetX()) * (pY-vert_next.GetY()) / (vert.GetY()-vert_next.GetY()) + vert_next.GetX()) )
84 vtkPlanes* frustum =
static_cast<vtkAreaPicker*
>(this->GetInteractor()->GetPicker())->GetFrustum();
86 vtkSmartPointer<vtkExtractGeometry> extractGeometry =
87 vtkSmartPointer<vtkExtractGeometry>::New();
88 extractGeometry->SetImplicitFunction(frustum);
89 #if VTK_MAJOR_VERSION <= 5 92 extractGeometry->SetInputData(
m_points);
94 extractGeometry->Update();
96 vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
97 vtkSmartPointer<vtkVertexGlyphFilter>::New();
98 glyphFilter->SetInputConnection(extractGeometry->GetOutputPort());
99 glyphFilter->Update();
101 vtkPolyData* selected = glyphFilter->GetOutput();
103 vtkIdTypeArray* ids = vtkIdTypeArray::SafeDownCast(selected->GetPointData()->GetArray(
"OriginalIds"));
104 m_selectedIds = vtkIdTypeArray::SafeDownCast(selected->GetPointData()->GetArray(
"OriginalIds"));
107 vtkSmartPointer<vtkCoordinate> coordinate = vtkSmartPointer<vtkCoordinate>::New();
108 coordinate->SetCoordinateSystemToWorld();
111 std::vector<int> selectedPolyPoints;
112 selectedPolyPoints.resize(ids->GetNumberOfTuples());
114 for (vtkIdType i = 0; i < ids->GetNumberOfTuples(); i++)
116 auto selectedPoint =
m_points->GetPoint(ids->GetValue(i));
117 coordinate->SetValue(selectedPoint[0], selectedPoint[1], selectedPoint[2]);
119 displayCoord = coordinate->GetComputedViewportValue(this->CurrentRenderer);
120 if (
isInside(polygonPoints, displayCoord[0], displayCoord[1]))
122 selectedPolyPoints.push_back(ids->GetValue(i));
126 #if VTK_MAJOR_VERSION <= 5 136 for(
auto selectedPolyPoint : selectedPolyPoints)
141 auto vertexFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
142 auto foo = vtkSmartPointer<vtkPoints>::New();
143 auto bar = vtkSmartPointer<vtkPolyData>::New();
151 m_points->vtkDataSet::GetPoint(i,point);
152 foo->InsertNextPoint(point);
158 vertexFilter->SetInputData(bar);
159 vertexFilter->Update();
161 auto polyData = vtkSmartPointer<vtkPolyData>::New();
162 polyData->ShallowCopy(vertexFilter->GetOutput());
164 #if VTK_MAJOR_VERSION <= 5 176 this->GetInteractor()->GetRenderWindow()->Render();
177 this->HighlightProp(
NULL);
187 ofstream outfile(
"Test.txt");
201 vtkRenderWindowInteractor *rwi = this->Interactor;
202 std::string key = rwi->GetKeySym();
211 QString label = QInputDialog::getItem(0,
"Select Label",
"Choose Label For SelectedPoints. You can press n to add a new Label:",
m_labelList , 0,
true, &accepted);
212 bool updateActors =
false;
216 for(vtkIdType i = 0; i <
m_selectedIds->GetNumberOfTuples(); i++)
237 auto newActor = vtkSmartPointer<vtkActor>::New();
239 newActor->GetProperty()->SetColor(
colors[labelIndex - 1][0] /255.0,
colors[labelIndex - 1][1] / 255.0,
colors[labelIndex - 1][2] / 255.0);
240 this->CurrentRenderer->RemoveActor(
m_labelActors[labelIndex - 1]);
244 this->CurrentRenderer->AddActor(newActor);
245 this->GetInteractor()->GetRenderWindow()->Render();
246 this->HighlightProp(
NULL);
255 QString label = QInputDialog::getItem(0,
"Modify Selected Points",
"Choose Label which should be modified:",
m_labelList , 0,
true, &accepted);
268 QString text = QInputDialog::getText(0,
"Insert New Label",
"New Label:",
QLineEdit::Normal,
"", &accepted);
275 foo2.push_back(std::vector<bool>(
m_points->GetNumberOfPoints(), 0));
279 auto mapper = vtkSmartPointer<vtkDataSetMapper>::New();
virtual void OnLeftButtonUp()
std::vector< bool > m_SelectedPoints
vtkStandardNewMacro(LVRLabelInteractorStyle)
void OnLeftButtonUp() override
bool isInside(std::vector< vtkVector2i > polygon, int &pX, int &pY)
virtual void OnRightButtonUp()
std::vector< std::vector< uint8_t > > colors
vtkSmartPointer< vtkIdTypeArray > m_selectedIds
void calculateSelection(bool select)
void OnLeftButtonDown() override
std::vector< vtkSmartPointer< vtkActor > > m_labelActors
vtkSmartPointer< vtkDataSetMapper > SelectedMapper
std::vector< std::vector< bool > > foo2
void labelSelectedPoints(QString label)
std::vector< uint8_t > m_pointLabels
vtkSmartPointer< vtkActor > SelectedActor
vtkSmartPointer< vtkPolyData > m_points
LVRLabelInteractorStyle()
virtual void OnRightButtonDown()
std::vector< vtkVector2i > GetPolygonPoints()