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