I’m vtk beginner , i have problems when i used vtkContourWidget with vtkOrientedGlyphFocalPlaneContourRepresentation . I want to create a contour on the screen coordinate, not world coordinate. so I write some code ,try to achieve it. But some problems makes me confused, there is only points but no line , and I do not know why this happeded.
Could anyone point out what my problem is? Thank you very much!
my vtk version is vtk 8.2
here is the code :
************************************* code ********************************************
#include “pch.h”
#include
#include <vtkSmartPointer.h>
#include <vtkContourWidget.h>
#include <vtkProperty.h>
#include <vtkProperty2D.h>
#include <vtkOrientedGlyphContourRepresentation.h>
#include <vtkPolyData.h>
#include <vtkCellArray.h>
#include <vtkPoints.h>
#include <vtkMath.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkOrientedGlyphFocalPlaneContourRepresentation.h>
#include <vtkContourLineInterpolator.h>
#include “vtkAutoInit.h”
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
int main()
{
vtkSmartPointer contourWidget =
vtkSmartPointer::New();
vtkSmartPointer< vtkOrientedGlyphFocalPlaneContourRepresentation> conRep =
vtkSmartPointer< vtkOrientedGlyphFocalPlaneContourRepresentation>::New();
conRep->GetLinesProperty()->SetColor(1, 1, 0);
conRep->GetLinesProperty()->SetLineWidth(5);
contourWidget->SetRepresentation(conRep);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->SetBackground(0.1, 0.2, 0.4);
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
interactor->SetInteractorStyle(style);
renderer->ResetCamera();
renderWindow->Render();
contourWidget->SetInteractor(interactor);
contourWidget->On();
conRep->ClosedLoopOn();
conRep->AddNodeAtDisplayPosition(100, 100);
conRep->AddNodeAtDisplayPosition(200, 100);
conRep->AddNodeAtDisplayPosition(200, 200);
conRep->AddNodeAtDisplayPosition(100, 200);
for (int i = 0; i < 4; i++) {
conRep->UpdateLines(i);
}
conRep->BuildRepresentation();
conRep->UpdateContour();
conRep->VisibilityOn();
contourWidget->SetWidgetState(vtkContourWidget::Manipulate);
interactor->Start();
return 0;
}
************************************* code ********************************************