<DIV><IMG src="cid:E26E9387@587E5070.F44DE050.jpg" filesize="33770" naturalW="484" naturalH="163"></DIV>
<DIV>what i want to do is just like above picture.</DIV>
<DIV>for now i just generate may fibres with out above operation:</DIV>
<DIV><IMG src="cid:DF18F789@587E5070.F44DE050.jpg" filesize="129373" naturalW="406" naturalH="414"></DIV>
<DIV> </DIV>
<DIV>i dont know how to do with each one cut and move like above. and i don't know how to save so many tubemapper as a stl file. </DIV>
<DIV> so what vtk function should i use? or any one give me example code.</DIV>
<DIV>my codes show as bellow:</DIV>
<DIV> </DIV>
<DIV>#include <vtkVersion.h><BR>#include <vtkSmartPointer.h><BR>#include <vtkRenderWindowInteractor.h><BR>#include <vtkRenderWindow.h><BR>#include <vtkRenderer.h><BR>#include <vtkActor.h><BR>#include <vtkProperty.h><BR>#include <vtkPolyDataMapper.h><BR>#include <vtkStripper.h><BR>#include <vtkCutter.h><BR>#include <vtkSplineFilter.h><BR>#include <vtkSpline.h><BR>#include <vtkPlane.h><BR>#include <vtkSphereSource.h><BR>#include <vtkPoints.h><BR>#include <vtkCellArray.h><BR>#include <vtkXMLPolyDataReader.h><BR>#include <vtkPolyData.h><BR>#include <vtkTubeFilter.h><BR>#include <vtkKochanekSpline.h><BR>#include <vtkMath.h><BR>#include"math.h"<BR>#include <vtkParametricSpline.h><BR>#include <vtkParametricFunctionSource.h><BR>#include <vtkInteractorStyleTrackballCamera.h><BR>#include <vtkPointSource.h></DIV>
<DIV>void normalize(float *a)<BR>{<BR> float length=sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);<BR> if(length>0)<BR> {<BR> a[0]=a[0]/length;<BR> a[1]=a[1]/length;<BR> a[2]=a[2]/length;<BR> }<BR> else<BR> {<BR> a[0]=0;<BR> a[1]=0;<BR> a[2]=0;<BR> }</DIV>
<DIV>}</DIV>
<DIV>float* cross(float* a,float *b,float *re)<BR>{</DIV>
<DIV> re[0]=a[1]*b[2]-a[2]*b[1];<BR> re[1]=a[2]*b[0]-a[0]*b[2];<BR> re[2]=a[0]*b[1]-a[1]*b[0];<BR> normalize(re);<BR> return re;<BR>}<BR>int main(int argc, char *argv[])<BR>{<BR> vtkMath::RandomSeed(1);<BR> float beta=1;<BR> float PI=3.1415926;<BR> int const N=5;<BR> int fibernumber=130;<BR> float fiberradius=0.1;<BR> float boxsize=10;<BR> float fiberlength=10;</DIV>
<DIV> </DIV>
<DIV> // Create a renderer, render window, and interactor<BR> vtkSmartPointer<vtkRenderer> renderer = <BR> vtkSmartPointer<vtkRenderer>::New();<BR> renderer->SetBackground(0.8,0.83,0.9);<BR> vtkSmartPointer<vtkRenderWindow> renderWindow = <BR> vtkSmartPointer<vtkRenderWindow>::New();<BR> renderWindow->AddRenderer(renderer);<BR> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = <BR> vtkSmartPointer<vtkRenderWindowInteractor>::New();<BR> renderWindowInteractor->SetRenderWindow(renderWindow);</DIV>
<DIV> vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =<BR> vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();<BR> renderWindowInteractor->SetInteractorStyle(style);</DIV>
<DIV><BR> for(int k=0;k<fibernumber;k++)<BR> {<BR> double x1=vtkMath::Random(0,1);<BR> double x2=vtkMath::Random(0,1);<BR> double x=vtkMath::Random(-boxsize/2.0,boxsize/2.0);<BR> double y=vtkMath::Random(-boxsize/2.0,boxsize/2.0);<BR> double z=vtkMath::Random(-boxsize/2.0,boxsize/2.0);<BR> double costheta=x1/sqrt(x1*x1-beta*beta*x1*x1+beta*beta);<BR> double theta=acos(costheta);<BR> double phi=2*PI*x2;</DIV>
<DIV> vtkSmartPointer<vtkPoints> points=<BR> vtkSmartPointer<vtkPoints>::New();<BR> points->SetNumberOfPoints(N);<BR> float step=fiberlength/N;<BR> float dx=sin(theta)*cos(phi);<BR> float dy=sin(theta)*sin(phi);<BR> float dz=cos(theta);<BR> float up[3]={0,0,1};<BR> float T[3]={dx,dy,dz};<BR> float N1[3],B1[3];<BR> cross(T,up,N1);<BR> cross(N1,T,B1);</DIV>
<DIV> float points2[N][3];<BR> for(int i=0;i<N;i++)<BR> {</DIV>
<DIV> points2[i][0]=x+(i-N/2)*dx*step;<BR> points2[i][1]=y+(i-N/2)*dy*step;<BR> points2[i][2]=z+(i-N/2)*dz*step;<BR> <BR> if(N%2!=0)<BR> {<BR> float offset=step/2.0;<BR> points2[i][0]+=-offset*dx;<BR> points2[i][1]+=-offset*dy;<BR> points2[i][2]+=-offset*dz;</DIV>
<DIV> }</DIV>
<DIV> if(i!=0&&i!=(N-1))<BR> {<BR> float angle=vtkMath::Random(0,2*PI);<BR> float altitude=vtkMath::Random(-fiberlength/8,fiberlength/8);<BR> points2[i][0]+=altitude*(N1[0]*cos(angle)+B1[0]*sin(angle));<BR> points2[i][1]+=altitude*(N1[1]*cos(angle)+B1[1]*sin(angle));<BR> points2[i][2]+=altitude*(N1[2]*cos(angle)+B1[2]*sin(angle));<BR> }</DIV>
<DIV> points->InsertPoint(i,points2[i][0],points2[i][1],points2[i][2]);<BR> //points->InsertNextPoint(points2[i]);<BR> }<BR> <BR> vtkSmartPointer<vtkCellArray> lines =<BR> vtkSmartPointer<vtkCellArray>::New();<BR> lines->InsertNextCell(N);<BR> for (int i = 0; i < N; i++)<BR> {<BR> lines->InsertCellPoint(i);<BR> }</DIV>
<DIV> vtkSmartPointer<vtkPolyData> polyData =<BR> vtkSmartPointer<vtkPolyData>::New();<BR> polyData->SetPoints(points);<BR> polyData->SetLines(lines);<BR> </DIV>
<DIV> vtkSmartPointer<vtkKochanekSpline> xSpline = <BR> vtkSmartPointer<vtkKochanekSpline>::New();<BR> xSpline->SetDefaultTension(0);<BR> vtkSmartPointer<vtkKochanekSpline> ySpline = <BR> vtkSmartPointer<vtkKochanekSpline>::New();<BR> ySpline->SetDefaultTension(0);<BR> vtkSmartPointer<vtkKochanekSpline> zSpline = <BR> vtkSmartPointer<vtkKochanekSpline>::New();<BR> zSpline->SetDefaultTension(0);</DIV>
<DIV> vtkSmartPointer<vtkParametricSpline> spline = <BR> vtkSmartPointer<vtkParametricSpline>::New();<BR> spline->SetXSpline(xSpline);<BR> spline->SetYSpline(ySpline);<BR> spline->SetZSpline(zSpline);<BR> spline->SetPoints(points);<BR> <BR> vtkSmartPointer<vtkParametricFunctionSource> functionSource = <BR> vtkSmartPointer<vtkParametricFunctionSource>::New();<BR> functionSource->SetParametricFunction(spline);<BR> functionSource->Update();</DIV>
<DIV> // Create a mapper and actor<BR> vtkSmartPointer<vtkPolyDataMapper> lineMapper = <BR> vtkSmartPointer<vtkPolyDataMapper>::New();<BR> lineMapper->SetInputConnection(functionSource->GetOutputPort());<BR> vtkSmartPointer<vtkActor> lineActor = <BR> vtkSmartPointer<vtkActor>::New();<BR> lineActor->GetProperty()->SetColor(1,0,1); // Give some color to the line<BR> lineActor->SetMapper(lineMapper);</DIV>
<DIV> // Create a tube (cylinder) around the line<BR> vtkSmartPointer<vtkTubeFilter> tubeFilter = <BR> vtkSmartPointer<vtkTubeFilter>::New();<BR> tubeFilter->SetInputConnection(functionSource->GetOutputPort());<BR> tubeFilter->SetRadius(fiberradius); //default is .5<BR> tubeFilter->SetNumberOfSides(15);<BR> tubeFilter->CappingOn();<BR> tubeFilter->Update();</DIV>
<DIV> // Create a mapper and actor<BR> vtkSmartPointer<vtkPolyDataMapper> tubeMapper = <BR> vtkSmartPointer<vtkPolyDataMapper>::New();<BR> tubeMapper->SetInputConnection(tubeFilter->GetOutputPort());<BR> vtkSmartPointer<vtkActor> tubeActor = <BR> vtkSmartPointer<vtkActor>::New();<BR> tubeActor->GetProperty()->SetOpacity(0.5); //Make the tube have some transparency.<BR> tubeActor->GetProperty()->SetColor(0.8,0.7,0.2);<BR> tubeActor->SetMapper(tubeMapper);</DIV>
<DIV> // Add the actor to the scene<BR> renderer->AddActor(tubeActor);<BR> renderer->AddActor(lineActor);<BR> <BR> }<BR> // Render and interact<BR> renderWindow->SetSize(600, 600);<BR> renderWindow->Render();<BR> renderWindowInteractor->Start();</DIV>
<DIV> return EXIT_SUCCESS;<BR>}</DIV>
<DIV> </DIV>