vtk撿選執行個體

來源:互聯網
上載者:User

#include "vtkCellPicker.h"
#include "vtkPointPicker.h"
#include "vtkAbstractMapper3D.h"
#include "vtkAssemblyPath.h"
#include "vtkProp3D.h"
class vtkMyCellPicker : public vtkCellPicker
{
public:
 vtkMyCellPicker();
 virtual ~vtkMyCellPicker();
public:
 void InsertLine(double a[3], double b[3], double c,vtkAssemblyPath* path, vtkProp3D* DD, vtkAbstractMapper3D * cc){IntersectWithLine(a,b,c,path,DD,cc);};

};

 

 

#include "vtkCommand.h"
#include "vtkPolyDataReader.h"
#include "vtkProperty.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkBoxWidget.h"

#include "vtkTransform.h"
#include "vtkLight.h"
#include  "vtkCamera.h"
#include "vtkDataSetMapper.h"
#include "vtkCellArray.h"
#include "vtkPlaneSource.h"
#include "vtkUnstructuredGridReader.h"
#include "vtkUnstructuredGrid.h"
#include "vtkGeometryFilter.h"
#include "vtkPolyDataNormals.h"
#include "vtkLODActor.h"
#include "vtkTextActor.h"
#include  "vtkTextProperty.h"
#include  "vtkPolyDataMapper2D.h"
#include "vtkIdFilter.h"
#include "vtkSelectVisiblePoints.h"
#include "vtkLabeledDataMapper.h"
#include "vtkCellCenters.h"
#include "vtkActor2D.h"
#include "vtkSphereSource.h"
#include "vtkIdList.h"
#include "vtkFloatArray.h"
#include "vtkIntArray.h"
#include "vtkLookupTable.h"
#include "vtkCellData.h"
#include  "vtkProperty2D.h"
#include "vtkTextProperty.h"

#include "vtkCellPicker.h"
#include "vtkAssemblyPath.h"
#include "vtkMyCellPicker.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern int x11,y11;
vtkRenderer * ren;
extern CRect rect;
vtkMyCellPicker *picker;

class vtkMyCallback : public vtkCommand
{
public:
  static vtkMyCallback *New()
    { return new vtkMyCallback; }
      virtual void Execute(vtkObject *caller, unsigned long, void*)
    {
    

                vtkRenderWindowInteractor *ir = (vtkRenderWindowInteractor*)(caller);
                int x = ir->GetEventPosition()[0];
                int y = ir->GetEventPosition()[1];
  
 
                picker->Pick(x,y,0.0,ren);
                vtkAssemblyPath *path;
                path = picker->GetPath();

    double cen[3];
          (  (vtkActor*)( path->GetFirstNode()->GetViewProp() )  )->GetMapper()->GetCenter(cen);
                double pos[3];                
         ren->GetActiveCamera()->GetPosition(pos);   
            vtkMapper *mm = (  (vtkActor*)( path->GetFirstNode()->GetViewProp() ) )->GetMapper();  
    picker->InsertLine(pos,cen,0.1, path,(vtkProp3D*)( path->GetFirstNode()->GetViewProp() ),mm );
    int id = picker->GetPointId();

    CString str;
    str.Format("%d",id);
    AfxMessageBox(str);
                if (path != NULL)
                {
                  (  (vtkActor*)( path->GetFirstNode()->GetViewProp() )  )->GetProperty()->SetColor(1.0,0.0,0.0);
                }

 

    }

   
};

 

CVTK::CVTK()
{
 //在建構函式中把各個vtk對象連成通道

//////////////////////////讀入資料

//在建構函式中把各個vtk對象連成通道
//////////////////////////////////
 
  //選點改變豔色,並且改變ID

        vtkSphereSource **Geometry = new vtkSphereSource*[5];
        vtkPolyDataMapper **mapper = new vtkPolyDataMapper*[5];
        vtkActor **actor = new vtkActor*[5];

        ren = vtkRenderer::New();

        renWin = vtkRenderWindow::New();

        picker = new vtkMyCellPicker();
        picker->SetTolerance(0.001);

        for (int j = 0; j < 5; j++)
        {     
              
          Geometry[j] = vtkSphereSource::New();
                   Geometry[j]->SetThetaResolution(16);
                   Geometry[j]->SetPhiResolution(8);
                   Geometry[j]->SetRadius(0.01);
                   Geometry[j]->SetCenter(j*0.1,0,0);
          
                   mapper[j] = vtkPolyDataMapper::New();
                   mapper[j]->SetInput(Geometry[j]->GetOutput());

                   actor[j] = vtkActor::New();
                   actor[j]->SetMapper(mapper[j]);

                           ren->AddActor(actor[j]);

 

               
        }

     vtkMyCallback *myCommand = vtkMyCallback::New();

    iren = vtkRenderWindowInteractor::New();

 vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();
 iren->SetInteractorStyle(style);

    iren->SetRenderWindow(renWin);
   

     renWin->AddRenderer(ren);
 

    iren->AddObserver(vtkCommand::LeftButtonPressEvent,myCommand);

 

 

       
       
 

  

  
 
/////////////////////////////////

 

 

 
}

CVTK::~CVTK()
{
 renWin->Delete();
// renderer->Delete();
// iren->Delete();
// cone->Delete();
// coneMapper->Delete();
// coneActor->Delete();
}

void CVTK::BeginRenderOn(CStatic * aStatic)
{
 CRect rect;
 aStatic->GetClientRect(&rect);
 renWin->SetSize(rect.Width(),rect.Height());
// renWin->SetWindowId(aStatic->m_hWnd );
 renWin->SetParentId(aStatic->m_hWnd);   //關鍵代碼一:設定父視窗
//    iren->Start();
 renWin->Render();                               // 關鍵代碼二:開始繪製,啟動互動器

}

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.