SFX2VTK.CPP

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 1.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 OpenFX Development Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 //  SFX2VTK.CPP
00025 
00026 SfxBound::SfxBound(){}
00027 
00028 SfxBound::~SfxBound(){}
00029 
00030 double SfxBound::GetMaximumSize(void){
00031  double s,sx,sy,sz,x,y,z;
00032  long i;
00033  double xmin,ymin,zmin,xmax,ymax,zmax;
00034  xmin = ymin = zmin =  1.e30;
00035  xmax = ymax = zmax = -1.e30;
00036  s = sx = sy = sz = 1.0;
00037  for(i=0;i<Nvert;i++){
00038    if((MainVp+i)->status == SELECTED){
00039      x = (float)((MainVp+i)->xyz[0])/((float)UNIT);
00040      y = (float)((MainVp+i)->xyz[1])/((float)UNIT);
00041      z = (float)((MainVp+i)->xyz[2])/((float)UNIT);
00042      if(x < xmin)xmin=x;
00043      if(y < ymin)ymin=y;
00044      if(z < zmin)zmin=z;
00045      if(x > xmax)xmax=x;
00046      if(y > ymax)ymax=y;
00047      if(z > zmax)zmax=z;
00048    }
00049  }
00050  sx = fabs(xmax - xmin);
00051  sy = fabs(ymax - ymin);
00052  sz = fabs(zmax - zmin);
00053  if(sx > s)s=sx;
00054  if(sy > s)s=sy;
00055  if(sz > s)s=sz;
00056  return s;
00057 }
00058 
00059 SfxReader::SfxReader()
00060 {
00061  Nv=Ne=Nf=0;
00062  scale=1.0;
00063 }
00064 
00065 SfxReader::~SfxReader()
00066 {
00067 }
00068 
00069 int SfxReader::GetNumberOfVertices(void){return (int)this->Nv;}
00070 int SfxReader::GetNumberOfEdge(void){return (int)this->Ne;}
00071 int SfxReader::GetNumberOfFaces(void){return (int)this->Nf;}
00072 void SfxReader::SetScale(double s){this->scale=s;}
00073 
00074 void SfxReader::Execute()
00075 {
00076   float x[3];
00077   int i,pts[3],count;
00078   vtkFloatPoints *newPoints;
00079   vtkCellArray *newTris;
00080   vtkPolyData *output = this->GetOutput();
00081   vtkIntScalars *vdata;
00082   if(NvertSelect == 0)return;
00083   newPoints = new vtkFloatPoints(NvertSelect);
00084   vdata     = new vtkIntScalars(NvertSelect);
00085   for(count=0,i=0;i<Nvert;i++){
00086     if((MainVp+i)->status == SELECTED){
00087       x[0] = (float)((MainVp+i)->xyz[0])*scale/((float)UNIT);
00088       x[1] = (float)((MainVp+i)->xyz[1])*scale/((float)UNIT);
00089       x[2] = (float)((MainVp+i)->xyz[2])*scale/((float)UNIT);
00090       (MainVp+i)->id=count++;
00091       newPoints->InsertNextPoint(x);
00092       vdata->InsertNextScalar(i);
00093       this->Nv++;
00094     }
00095   }
00096   face *fp;
00097   for(i=0,count=0;i<Nface;i++){
00098     fp=(MainFp+i);
00099     if((MainVp+fp->V[0])->status == SELECTED &&
00100        (MainVp+fp->V[1])->status == SELECTED &&
00101        (MainVp+fp->V[2])->status == SELECTED)count++;
00102   }
00103   newTris = new vtkCellArray;
00104   newTris->Allocate(count);
00105   for(i=0;i<Nface;i++){
00106     fp=(MainFp+i);
00107     if((MainVp+fp->V[0])->status == SELECTED &&
00108        (MainVp+fp->V[1])->status == SELECTED &&
00109        (MainVp+fp->V[2])->status == SELECTED){
00110       pts[0] = (int)((MainVp+fp->V[0])->id);
00111       pts[1] = (int)((MainVp+fp->V[1])->id);
00112       pts[2] = (int)((MainVp+fp->V[2])->id);
00113       newTris->InsertNextCell(3,pts);
00114       this->Nf++;
00115     }
00116   }
00117   output->SetPoints(newPoints);
00118   newPoints->Delete();
00119   output->SetPolys(newTris);
00120   newTris->Delete();
00121   output->GetPointData()->SetScalars(vdata);
00122   vdata->Delete();
00123   output->Squeeze();
00124 //MessageBox(NULL,"SfxReader Finished",NULL,MB_OK);
00125 }
00126 
00127 SfxPointReader::SfxPointReader()
00128 {
00129  Nv=0;
00130  scale=1.0;
00131 }
00132 
00133 SfxPointReader::~SfxPointReader()
00134 {
00135 }
00136 
00137 void SfxPointReader::SetScale(double s){this->scale=s;}
00138 
00139 void SfxPointReader::Execute()
00140 {
00141   float x[3];
00142   int i,pts[2],count;
00143   vtkFloatPoints *newPoints;
00144   vtkCellArray *newTris;
00145   vtkPolyData *output = this->GetOutput();
00146   vtkIntScalars *vdata;
00147   if(NvertSelect == 0)return;
00148   newPoints = new vtkFloatPoints(NvertSelect);
00149   vdata     = new vtkIntScalars(NvertSelect);
00150   for(count=0,i=0;i<Nvert;i++){
00151     if((MainVp+i)->status == SELECTED){
00152       x[0] = (float)((MainVp+i)->xyz[0])*scale/((float)UNIT);
00153       x[1] = (float)((MainVp+i)->xyz[1])*scale/((float)UNIT);
00154       x[2] = (float)((MainVp+i)->xyz[2])*scale/((float)UNIT);
00155       (MainVp+i)->id=count++;
00156       newPoints->InsertNextPoint(x);
00157       vdata->InsertNextScalar(i);
00158       this->Nv++;
00159     }
00160   }
00161   newTris = new vtkCellArray;
00162   newTris->Allocate(count);
00163   for(i=0;i<Nvert;i++){
00164     if((MainVp+i)->status == SELECTED){
00165       pts[0] = (int)((MainVp+i)->id);
00166       newTris->InsertNextCell(1);
00167       newTris->InsertCellPoint(pts[0]);
00168     }
00169   }
00170   output->SetPoints(newPoints);
00171   newPoints->Delete();
00172   output->SetVerts(newTris);
00173   newTris->Delete();
00174   output->GetPointData()->SetScalars(vdata);
00175   vdata->Delete();
00176   output->Squeeze();
00177 }
00178 
00179 
00180 SfxEdgeReader::SfxEdgeReader()
00181 {
00182  Nv=0; Ne=0;
00183  scale=1.0;
00184 }
00185 
00186 SfxEdgeReader::~SfxEdgeReader()
00187 {
00188 }
00189 
00190 void SfxEdgeReader::SetScale(double s){this->scale=s;}
00191 
00192 void SfxEdgeReader::Execute()
00193 {
00194   float x[3];
00195   int i,pts[2],count;
00196   vtkFloatPoints *newPoints;
00197   vtkCellArray *newTris;
00198   vtkPolyData *output = this->GetOutput();
00199   vtkIntScalars *vdata;
00200   if(NvertSelect == 0)return;
00201   newPoints = new vtkFloatPoints(NvertSelect);
00202   vdata     = new vtkIntScalars(NvertSelect);
00203   for(count=0,i=0;i<Nvert;i++){
00204     if((MainVp+i)->status == SELECTED){
00205       x[0] = (float)((MainVp+i)->xyz[0])*scale/((float)UNIT);
00206       x[1] = (float)((MainVp+i)->xyz[1])*scale/((float)UNIT);
00207       x[2] = (float)((MainVp+i)->xyz[2])*scale/((float)UNIT);
00208       (MainVp+i)->id=count++;
00209       newPoints->InsertNextPoint(x);
00210       vdata->InsertNextScalar(i);
00211       this->Nv++;
00212     }
00213   }
00214   edge *ep;
00215   for(i=0,count=0,ep=MainEp;i<Nedge;i++){
00216     if((MainVp+ep->V[0])->status == SELECTED &&
00217        (MainVp+ep->V[1])->status == SELECTED)count++;
00218     ep++;
00219   }
00220   newTris = new vtkCellArray;
00221   newTris->Allocate(count);
00222   for(i=0,ep=MainEp;i<Nedge;i++){
00223     if((MainVp+ep->V[0])->status == SELECTED &&
00224        (MainVp+ep->V[1])->status == SELECTED){
00225       pts[0] = (int)((MainVp+ep->V[0])->id);
00226       pts[1] = (int)((MainVp+ep->V[1])->id);
00227       newTris->InsertNextCell(2,pts);
00228       this->Ne++;
00229     }
00230     ep++;
00231   }
00232   output->SetPoints(newPoints);
00233   newPoints->Delete();
00234   output->SetPolys(newTris);
00235   newTris->Delete();
00236   output->GetPointData()->SetScalars(vdata);
00237   vdata->Delete();
00238   output->Squeeze();
00239 }
00240 
00241 SfxBaseWriter::SfxBaseWriter()
00242 {
00243   this->Input = NULL;
00244 }
00245 
00246 void SfxBaseWriter::Write()
00247 {
00248   if ( !this->Input ) {
00249     return;
00250   }
00251   this->Input->Update();
00252   this->WriteData();
00253   this->Input->ReleaseData();
00254 }
00255 
00256 void SfxBaseWriter::Update()
00257 {
00258   this->Write();
00259 }
00260 
00261 SfxWriter::SfxWriter()
00262 {
00263  Nv=0; Ne=0; Nf=0;
00264  scale=1.0;
00265 }
00266 
00267 SfxWriter::~SfxWriter()
00268 {
00269 }
00270 
00271 void SfxWriter::SetScale(double s){this->scale=s;}
00272 int SfxWriter::GetNumberOfVertices(void){return (int)this->Nv;}
00273 int SfxWriter::GetNumberOfEdge(void){return (int)this->Ne;}
00274 int SfxWriter::GetNumberOfFaces(void){return (int)this->Nf;}
00275 
00276 void SfxWriter::SetInput(vtkPolyData *input)
00277 {
00278   if ( this->Input != input )
00279     {
00280     this->Input = (vtkDataSet *) input;
00281     this->Modified();
00282     }
00283 }
00284 
00285 void SfxWriter::WriteData()
00286 {
00287   vtkPoints *pts;
00288   vtkCellArray *polys;
00289   vtkPolyData *input=(vtkPolyData *)this->Input;
00290 
00291   if ( (pts = input->GetPoints()) == NULL ||
00292   (polys = input->GetPolys()) == NULL ){
00293     return;
00294   }
00295   vertex *Vp;
00296   face   *Fp;
00297   float p[3];
00298   int i,npts,npolys;
00299   long BaseVert;
00300   BaseVert=Nvert;
00301   npts=input->GetNumberOfPoints();
00302   npolys=input->GetNumberOfPolys();
00303   this->Nv=npts;
00304   this->Nf=npolys;
00305   if(npts > 0){
00306     if(!UpdateVertexHeap(Nvert+npts))return;
00307     for(i=0;i<npts;i++){
00308       pts->GetPoint(i,p);
00309       CreateVertex();
00310       Vp=(MainVp+Nvert-1);
00311       Vp->id=0;
00312       Vp->sp=NULL;
00313       Vp->xyz[0]=(long)(p[0]*(float)UNIT*scale);
00314       Vp->xyz[1]=(long)(p[1]*(float)UNIT*scale);
00315       Vp->xyz[2]=(long)(p[2]*(float)UNIT*scale);
00316     }
00317   }
00318   if(npolys > 0){
00319     int *indx;
00320     if(!UpdateFaceHeap(Nface+npolys))return;
00321     for (polys->InitTraversal(); polys->GetNextCell(npts,indx); ){
00322       CreateFace(BaseVert+(long)indx[0],
00323                  BaseVert+(long)indx[1],
00324                  BaseVert+(long)indx[2]);
00325       this->InsertInVertexList(BaseVert,indx[0],indx[1]);
00326       this->InsertInVertexList(BaseVert,indx[1],indx[2]);
00327       this->InsertInVertexList(BaseVert,indx[2],indx[0]);
00328     }
00329     this->BuildEdges(BaseVert);
00330   }
00331 }
00332 
00333 // Use the vertex's skeleton pointer and integer identifer as temporary
00334 // storage for build edge adjacency lists since they are not uses on new
00335 // vertices.
00336 //
00337 void SfxWriter::InsertInVertexList(long base, long Vj, long Vi){
00338  vertex *vj,*vi;
00339  long *list,i,j;
00340  vj=(MainVp+base+Vj);
00341  vi=(MainVp+base+Vi);
00342  list = (long *)vi->sp;
00343  if(vi->id > 0)for(i=0;i<vi->id;i++)if(list[i] == Vj)return;
00344  list = (long *)vj->sp;
00345  if(vj->id > 0)for(j=0;j<vj->id;j++)if(list[j] == Vi)return;
00346  if(vi->id == 0){
00347    if((list = (long *)X__Malloc((vi->id + 1)*sizeof(long))) == NULL){
00348      return;
00349    }
00350    vi->sp=(struct Designer_SKELETON_tag *)list;
00351  }
00352  else{
00353    list = (long *)vi->sp;
00354    if((list = (long *)X__Realloc(list,(vi->id + 1)*sizeof(long))) == NULL){
00355      return;
00356    }
00357    vi->sp=(struct Designer_SKELETON_tag *)list;
00358  }
00359  list[vi->id] = base+Vj;
00360  (vi->id)++;
00361 }
00362 
00363 void SfxWriter::BuildEdges(long base){
00364  long n,j,i,*list;
00365  vertex *vp;
00366  vp=(MainVp+base);
00367  for(j=base;j<Nvert;j++){
00368    if(vp->id != 0 && vp->sp != NULL){
00369      if(!UpdateEdgeHeap(Nedge+vp->id))return;
00370      list = (long *)vp->sp;
00371      for(i=0;i<vp->id;i++)CreateEdge(j,list[i]);
00372      X__Free(vp->sp); vp->sp=NULL; vp->id=0;
00373    }
00374    vp++;
00375  }
00376 }
00377 
00378 void SfxWriter::EraseOldStructure(long base){
00379  long c;
00380  vertex *vp;
00381  vp=(MainVp+base); for(c=base;c<Nvert;c++){
00382    if(vp->status == SELECTED){
00383      vp->status=INEDITOR; NvertSelect--; NvertDeselect++;
00384    }
00385    vp++;
00386  }
00387  EraseVertex(1);
00388  vp=MainVp; for(c=0;c<Nvert;c++){
00389    if(vp->status == INEDITOR){
00390      vp->status=SELECTED; NvertSelect++; NvertDeselect--;
00391    }
00392    vp++;
00393  }
00394 }
00395 
00396 void SfxWriter::OffsetStructure(long base, long dx, long dy, long dz){
00397  long c;
00398  vertex *vp;
00399  vp=(MainVp+base); for(c=base;c<Nvert;c++){
00400    vp->xyz[0] += dx;
00401    vp->xyz[1] += dy;
00402    vp->xyz[2] += dz;
00403    vp++;
00404  }
00405 }

Generated on Sun Apr 27 14:20:11 2014 for OpenFX by  doxygen 1.5.6