Fix Square legend render bug.
This commit is contained in:
@@ -18,17 +18,22 @@ vtkStandardNewMacro(ResliceSquareLegendActor)
|
||||
void ResliceSquareLegendActor::BuildShape(vtkRenderer *renderer) {
|
||||
int* sizes = renderer->GetSize();
|
||||
Square->SetDisplayPosition(sizes[0]-20,sizes[1]-20);
|
||||
CheckSquare->SetDisplayPosition(sizes[0]-15,sizes[1]-15);
|
||||
}
|
||||
|
||||
void ResliceSquareLegendActor::ReleaseGraphicsResources(vtkWindow * window) {
|
||||
Square->ReleaseGraphicsResources(window);
|
||||
CheckSquare->ReleaseGraphicsResources(window);
|
||||
}
|
||||
|
||||
int ResliceSquareLegendActor::RenderOverlay(vtkViewport *viewport) {
|
||||
auto renderer = vtkRenderer::SafeDownCast(viewport);
|
||||
if (renderer){
|
||||
BuildShape(renderer);
|
||||
return Square->RenderOverlay(viewport);
|
||||
int ret = Square->RenderOverlay(viewport);
|
||||
if (Checked)
|
||||
CheckSquare->RenderOverlay(viewport);
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -43,9 +48,9 @@ ResliceSquareLegendActor::ResliceSquareLegendActor() {
|
||||
vtkNew<vtkPoints> pts;
|
||||
pts->SetNumberOfPoints(4);
|
||||
pts->SetPoint(0,0,0,0);
|
||||
pts->SetPoint(1,18,0,0);
|
||||
pts->SetPoint(2,18,18,0);
|
||||
pts->SetPoint(3,0,18,0);
|
||||
pts->SetPoint(1,20,0,0);
|
||||
pts->SetPoint(2,20,20,0);
|
||||
pts->SetPoint(3,0,20,0);
|
||||
polydata->SetPoints(pts);
|
||||
vtkNew<vtkPolygon> polygon;
|
||||
polygon->GetPointIds()->SetNumberOfIds(4);
|
||||
@@ -64,6 +69,35 @@ ResliceSquareLegendActor::ResliceSquareLegendActor() {
|
||||
Square->GetProperty()->SetLineWidth(0);
|
||||
Square->GetProperty()->SetPointSize(0);
|
||||
|
||||
CheckSquare = vtkActor2D::New();
|
||||
CheckSquare->Register(this);
|
||||
CheckSquare->Delete();
|
||||
vtkNew<vtkPolyDataMapper2D> mapper2;
|
||||
vtkNew<vtkPolyData> polydata2;
|
||||
vtkNew<vtkPoints> pts2;
|
||||
pts2->SetNumberOfPoints(4);
|
||||
pts2->SetPoint(0,0,0,0);
|
||||
pts2->SetPoint(1,10,0,0);
|
||||
pts2->SetPoint(2,10,10,0);
|
||||
pts2->SetPoint(3,0,10,0);
|
||||
polydata2->SetPoints(pts2);
|
||||
vtkNew<vtkPolygon> polygon2;
|
||||
polygon2->GetPointIds()->SetNumberOfIds(4);
|
||||
polygon2->GetPointIds()->SetId(0,0);
|
||||
polygon2->GetPointIds()->SetId(1,1);
|
||||
polygon2->GetPointIds()->SetId(2,2);
|
||||
polygon2->GetPointIds()->SetId(3,3);
|
||||
|
||||
vtkNew<vtkCellArray> cells2;
|
||||
cells2->InsertNextCell(polygon2);
|
||||
|
||||
polydata2->SetPolys(cells2);
|
||||
mapper2->SetInputData(polydata2);
|
||||
CheckSquare->SetMapper(mapper2);
|
||||
|
||||
CheckSquare->GetProperty()->SetLineWidth(0);
|
||||
CheckSquare->GetProperty()->SetPointSize(0);
|
||||
|
||||
}
|
||||
|
||||
ResliceSquareLegendActor::~ResliceSquareLegendActor() {
|
||||
|
||||
@@ -53,6 +53,9 @@ public:
|
||||
vtkTypeBool HasTranslucentPolygonalGeometry() override { return 0; }
|
||||
|
||||
vtkProperty2D* GetProperty();
|
||||
|
||||
vtkSetMacro(Checked,bool);
|
||||
vtkGetMacro(Checked,bool);
|
||||
protected:
|
||||
ResliceSquareLegendActor();
|
||||
|
||||
@@ -64,6 +67,9 @@ private:
|
||||
void operator=(const ResliceSquareLegendActor &) = delete;
|
||||
|
||||
vtkActor2D * Square;
|
||||
vtkActor2D * CheckSquare;
|
||||
|
||||
bool Checked = false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user