Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to cut a png image in vtk by Qt..!



  • i have done a code but for the png the mapping is some what different ,
    see the last four lines of the code

    callback->Plane=plane;
    callback->Actor=pngActor;
    ///////callback->mapper=pngMapper;//////// this is the line which i have commit some mistake ..but ,i dontknow how to resolve this

    i have a error like this
    : error: cannot convert 'vtkSmartPointer<vtkDataSetMapper>' to 'vtkPolyDataMapper*' in assignment

    and this is my code,

           #include <vtkSmartPointer.h>
          // For the rendering pipeline setup:
            #include <vtkConeSource.h>
          #include <vtkPNGReader.h>
        #include <vtkDataSetMapper.h>
          #include <vtkClipDataSet.h>
          #include <vtkDataSetMapper.h>
          #include <vtkPolyDataMapper.h>
         #include <vtkActor.h>
        #include <vtkRenderer.h>
       #include <vtkRenderWindow.h>
       #include <vtkRenderWindowInteractor.h>
          #include <vtkInteractorStyleTrackballCamera.h>
    

    // For boxthreed:
    //#include <boxthreed.h>
    #include <vtkCommand.h>
    #include <vtkTransform.h>
    #include <vtkPlane.h>
    #include <vtkClipPolyData.h>
    #include "boxthreed.h"
    #include "planerep.h"

    class vtkMyCallback : public vtkCommand
    {public: static
    vtkMyCallback *New()
    { return new vtkMyCallback;
    } virtual void Execute( vtkObject caller, unsigned long, void )
    {
    vtkSmartPointer<vtkTransform> t =
    vtkSmartPointer<vtkTransform>::New();
    boxthreed widget = reinterpret_cast<boxthreed>(caller);
    widget->GetTransform( t );
    // widget->GetPlanes(this->Plane);
    // widget->getmapper(this->mapper);

    // widget->GetProp3D()->SetUserTransform( t );

    }
    

    vtkMyCallback():Plane(0),Actor(0){}
    vtkPlane *Plane;
    vtkActor *Actor;
    vtkPolyDataMapper *mapper;
    // vtkDataSetMapper *mapper;
    };

    int main( int vtkNotUsed( argc ), char* vtkNotUsed( argv )[] )
    {
    // vtkSmartPointer<vtkConeSource> cone =
    // vtkSmartPointer<vtkConeSource>::New();

    vtkSmartPointer<vtkPNGReader> pngreader =
      vtkSmartPointer<vtkPNGReader>::New();
      pngreader->SetFileName("/home/sara/Desktop/sankar/vtk/png  /imagee.png");
    

    vtkSmartPointer<vtkPlane> plane =
    vtkSmartPointer<vtkPlane>::New();

    vtkSmartPointer<vtkClipDataSet> clipper =
    vtkSmartPointer<vtkClipDataSet>::New();
    // clipper->SetClipFunction(plane);
    clipper->InsideOutOn();
    clipper->SetInputConnection(pngreader->GetOutputPort());

    vtkSmartPointer<vtkDataSetMapper> pngMapper =
    vtkSmartPointer<vtkDataSetMapper>::New();
    pngMapper->SetInputConnection( pngreader->GetOutputPort() );
    // pngMapper->SetInputConnection(clipper->GetOutputPort());

    // pngMapper->AddClippingPlane(plane);

    vtkSmartPointer<vtkActor> pngActor =
    vtkSmartPointer<vtkActor>::New();
    pngActor->SetMapper( pngMapper );

    vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor( pngActor );
    renderer->SetBackground( 0.1, 0.2, 0.4 );

    vtkSmartPointer<vtkRenderWindow> window =
    vtkSmartPointer<vtkRenderWindow>::New();
    window->AddRenderer( renderer );
    window->SetSize( 300, 300 );

    vtkSmartPointer<vtkRenderWindowInteractor> interactor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactor->SetRenderWindow( window );

    vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
    vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
    interactor->SetInteractorStyle( style );

    vtkSmartPointer<boxthreed> boxWidget =
    vtkSmartPointer<boxthreed>::New();
    boxWidget->SetInteractor( interactor );
    boxWidget->SetProp3D( pngActor );

    boxWidget->SetPlaceFactor( 1.25 );
    // Make the box 1.25x larger than the actor
    boxWidget->PlaceWidget();
    vtkSmartPointer<vtkMyCallback> callback =
    vtkSmartPointer<vtkMyCallback>::New();
    callback->Plane=plane;
    callback->Actor=pngActor;
    callback->mapper=pngMapper;
    boxWidget->AddObserver( vtkCommand::InteractionEvent, callback );
    boxWidget->On();
    interactor->Start();

    return EXIT_SUCCESS;
    }


  • Lifetime Qt Champion

    @sankarapandiyan said in how to cut a png image in vtk by Qt..!:

    : error: cannot convert 'vtkSmartPointer<vtkDataSetMapper>' to 'vtkPolyDataMapper*' in assignment

    It's completely unrelated to Qt. You're assigning a variable of wrong type.



  • @jsulm i have build a vtk here in qt


  • Lifetime Qt Champion

    @sankarapandiyan So what?

    callback->Plane=plane;
    callback->Actor=pngActor;
    ///////callback->mapper=pngMapper;
    

    This isn't related to Qt. This is code using VTK not Qt.



  • @jsulm yes sure this is the vtk code ... but implemented in qt only .. thats why i post a ques here ..


  • Lifetime Qt Champion

    @sankarapandiyan Take a look at the error message and fix your code.
    "but implemented in qt only" - Qt is not a programming language, you're implementing it in C++.



  • @jsulm yes sure ... but for png we have using different mappers and for poly data image we are using different mappers that is the problem i dont know how to create mappers of the different one with seperately/...


  • Lifetime Qt Champion

    @sankarapandiyan I guess you need to get the RAW pointer (vtkDataSetMapper*) from vtkSmartPointer<vtkDataSetMapper> and assign it and not the vtkSmartPointer



  • @jsulm ok sure yes you are right..



  • @jsulm sure.. i will try


Log in to reply