当前位置: 首页>>代码示例>>C++>>正文


C++ RegionType::GetUpperIndex方法代码示例

本文整理汇总了C++中imagetype::RegionType::GetUpperIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ RegionType::GetUpperIndex方法的具体用法?C++ RegionType::GetUpperIndex怎么用?C++ RegionType::GetUpperIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imagetype::RegionType的用法示例。


在下文中一共展示了RegionType::GetUpperIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: save

void Mesh::save(string filename, ImageType::Pointer image_ref)
{
	vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
	vtkSmartPointer<vtkDoubleArray> pointNormalsArray = vtkSmartPointer<vtkDoubleArray>::New();
	pointNormalsArray->SetNumberOfComponents(3); //3d normals (ie x,y,z)
	pointNormalsArray->SetNumberOfTuples(points_.size());
	CVector3 p, n;
	for (unsigned int i=0; i<points_.size(); i++) {
		p = points_[i]->getPosition();
		n = points_[i]->getNormal();
		points->InsertNextPoint(p[0],p[1],p[2]);
		pointNormalsArray->SetTuple3(i, n[0], n[1], n[2]) ;
	}
	vtkSmartPointer<vtkPolyData> source = vtkSmartPointer<vtkPolyData>::New();
	source->SetPoints(points);
	source->GetPointData()->SetNormals(pointNormalsArray);
	source->Allocate(triangles_.size());
	for (unsigned int i=0; i<triangles_.size(); i+=3) {
		vtkIdType pts[3] = {triangles_[i],triangles_[i+1],triangles_[i+2]};
		source->InsertNextCell(VTK_TRIANGLE,3,pts);
	}
    
    if (image_ref.IsNotNull())
    {
        ImageType::RegionType largestRegion = image_ref->GetLargestPossibleRegion();
        ImageType::IndexType downSliceIndex, downSliceMIndex, upperSliceIndex, upperSliceMIndex;
        downSliceIndex.Fill(0);
        downSliceMIndex.Fill(0);
        downSliceMIndex[1] = 1;
        upperSliceIndex = largestRegion.GetUpperIndex();
        upperSliceMIndex = upperSliceIndex; upperSliceMIndex[1] = upperSliceMIndex[1]-1;
        PointType downSlicePoint, downSliceMPoint, upperSlicePoint, upperSliceMPoint;
        image_ref->TransformIndexToPhysicalPoint(downSliceIndex, downSlicePoint);
        image_ref->TransformIndexToPhysicalPoint(downSliceMIndex, downSliceMPoint);
        image_ref->TransformIndexToPhysicalPoint(upperSliceIndex, upperSlicePoint);
        image_ref->TransformIndexToPhysicalPoint(upperSliceMIndex, upperSliceMPoint);
        
        CVector3 downSliceNormal = CVector3(downSlicePoint[0]-downSliceMPoint[0],downSlicePoint[1]-downSliceMPoint[1],downSlicePoint[2]-downSliceMPoint[2]).Normalize(), upperSliceNormal = CVector3(upperSlicePoint[0]-upperSliceMPoint[0],upperSlicePoint[1]-upperSliceMPoint[1],upperSlicePoint[2]-upperSliceMPoint[2]).Normalize();
        
        vtkSmartPointer<vtkPlane> downPlane = vtkSmartPointer<vtkPlane>::New(), upperPlane = vtkSmartPointer<vtkPlane>::New();
        downPlane->SetOrigin(downSlicePoint[0],downSlicePoint[1],downSlicePoint[2]);
        downPlane->SetNormal(downSliceNormal[0],downSliceNormal[1],downSliceNormal[2]);
        upperPlane->SetOrigin(upperSlicePoint[0],upperSlicePoint[1],upperSlicePoint[2]);
        upperPlane->SetNormal(upperSliceNormal[0],upperSliceNormal[1],upperSliceNormal[2]);
    
        vtkSmartPointer<vtkClipPolyData> downClipper = vtkSmartPointer<vtkClipPolyData>::New();
        downClipper->SetInputData(source);
        downClipper->SetClipFunction(downPlane);
        downClipper->InsideOutOn();
        downClipper->Update();
    
        vtkSmartPointer<vtkClipPolyData> upperClipper = vtkSmartPointer<vtkClipPolyData>::New();
        upperClipper->SetInputData(downClipper->GetOutput());
        upperClipper->SetClipFunction(upperPlane);
        upperClipper->InsideOutOn();
        upperClipper->Update();
        source = upperClipper->GetOutput();
    }
    
	vtkSmartPointer<vtkPolyDataWriter> writer = vtkSmartPointer<vtkPolyDataWriter>::New();
	writer->SetFileName(filename.c_str());
	writer->SetInputData(source);
	writer->Write();
}
开发者ID:H-Snoussi,项目名称:spinalcordtoolbox,代码行数:64,代码来源:Mesh.cpp


注:本文中的imagetype::RegionType::GetUpperIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。