int main() { BEGIN_TESTING(vtk VoxRaytracer); // muon scatter // MuonScatter muon; muon.LineIn().origin() << -6, 12, -6, 1; muon.LineIn().direction() << 1 , -1 , 1 , 0; muon.LineOut().origin() << 6 , -4 , 6 , 1; muon.LineOut().direction() << 1 , -1 , 1 , 0; Vtk::vtkMuonScatter v_muon(muon); // structured grid // ImageData grid(Vector3i(12,10,12)); grid.SetSpacing(Vector3f(1,1,1)); grid.SetPosition(Vector3f(0,0,0)); Vtk::vtkStructuredGrid v_grid(grid); // voxraytracer // VoxRaytracer rt(grid); Vector4f pt; rt.GetEntryPoint(muon.LineIn(),pt); std::cout << pt.transpose() << "\n"; Vtk::vtkVoxRaytracerRepresentation v_rt(rt); v_rt.SetMuon(muon); v_rt.SetRayColor(Vector4f(1,0,0,1)); // // renderer // Vtk::Viewer viewer; // widget // vtkBoxWidget *widget = v_grid.GetWidget(); vtkWidgetCallback *cbk = vtkWidgetCallback::New(); cbk->SetTracer(&v_rt); cbk->SetMuon(&muon); cbk->SetAnnotation(viewer.GetAnnotation()); widget->AddObserver(vtkCommand::InteractionEvent, cbk); widget->SetInteractor(viewer.GetInteractor()); widget->PlaceWidget(); widget->On(); viewer.AddPuppet(v_grid); viewer.AddPuppet(v_rt); viewer.AddPuppet(v_muon); viewer.Start(); END_TESTING; }
void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon, HPoint3f poca) { HPoint3f pt1,pt2,src; src = muon.LineIn().origin; d->m_Content->GetEntryPoint(muon.LineIn(),pt1); d->m_Sphere1->SetCenter(pt1(0),pt1(1),pt1(2)); d->m_Line1->SetPoint1(src(0),src(1),src(2)); d->m_Line1->SetPoint2(pt1(0),pt1(1),pt1(2)); HLine3f line_out = muon.LineOut(); src = line_out.origin; float *direction = line_out.direction.data(); for(int i=0;i<3;++i) direction[i] *= -1; d->m_Content->GetEntryPoint(line_out,pt2); d->m_Sphere2->SetCenter(pt2(0),pt2(1),pt2(2)); d->m_Line2->SetPoint1(src(0),src(1),src(2)); d->m_Line2->SetPoint2(pt2(0),pt2(1),pt2(2)); d->m_Line3->SetPoint1(pt1(0),pt1(1),pt1(2)); d->m_Line3->SetPoint2(pt2(0),pt2(1),pt2(2)); // Create a vtkPoints object and store the points in it vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); points->InsertNextPoint(pt1(0),pt1(1),pt1(2)); points->InsertNextPoint(poca(0),poca(1),poca(2)); points->InsertNextPoint(pt2(0),pt2(1),pt2(2)); // Create a cell array to store the lines in and add the lines to it vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New(); for(unsigned int i = 0; i < 2; i++) { vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New(); line->GetPointIds()->SetId(0,i); line->GetPointIds()->SetId(1,i+1); lines->InsertNextCell(line); } // Create a polydata to store everything in vtkSmartPointer<vtkPolyData> linesPolyData = vtkSmartPointer<vtkPolyData>::New(); // Add the points to the dataset linesPolyData->SetPoints(points); // Add the lines to the dataset linesPolyData->SetLines(lines); d->m_RayLine->RemoveAllInputs(); # if VTK_MAJOR_VERSION <= 5 d->m_RayLine->AddInputConnection(linesPolyData->GetProducerPort()); # else d->m_RayLine->AddInputData(linesPolyData); # endif d->m_RayLine->AddInputConnection(d->m_Line1->GetOutputPort()); d->m_RayLine->AddInputConnection(d->m_Sphere1->GetOutputPort()); d->m_RayLine->AddInputConnection(d->m_Line2->GetOutputPort()); d->m_RayLine->AddInputConnection(d->m_Sphere2->GetOutputPort()); // d->m_RayLine->AddInputConnection(d->m_Line3->GetOutputPort()); vtkSmartPointer<vtkSphereSource> poca_sphere = vtkSmartPointer<vtkSphereSource>::New(); poca_sphere->SetRadius(d->default_radius); poca_sphere->SetCenter(poca(0),poca(1),poca(2)); d->m_RayLine->AddInputConnection(poca_sphere->GetOutputPort()); vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New(); Matrix4f mat = d->m_Content->GetImage()->GetWorldMatrix(); for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) vmat->SetElement(i,j,mat(i,j)); d->m_Transform->SetMatrix(vmat); if(d->m_Content->GetImage()->IsInsideBounds(poca)) this->SetRay(pt1,poca,pt2); else this->SetRay(pt1,pt2); }