Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

SparseImage3D.cpp

Go to the documentation of this file.
00001 /* ImLib3D
00002  * Copyright (c) 2001, ULP-IPB Strasbourg.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00021 // *******************************************************
00022 // template implementations for SparseImage3D
00023 // *******************************************************
00024 
00025 #include<ImLib3D/SparseImage3D.hpp>
00026 #include<ImLib3D/XMLTools.hpp>
00027 
00028 
00029 
00030 vector<const SparseStructure3D *> SparseStructure3D::allreadyExisting;
00031 void 
00032 SparseStructure3D::Read( ImLib3DFile *file,xmlpp::Element *parentNode,xmlpp::Element *node)
00033 {
00034     node=CreateReadNode("SparseStructure3D",file,parentNode,node);
00035     mask.Read(file,node);
00036 }
00037 void 
00038 SparseStructure3D::Write(ImLib3DFile *file,xmlpp::Element *parentNode,xmlpp::Element *node) const
00039 {
00040     node=CreateWriteNode("SparseStructure3D",file,parentNode,node);
00041     mask.Write(file,node);
00042 }
00043 
00044 
00045 bool 
00046 SparseStructure3D::Dereference(SparseImage3DBase *image) const 
00047 {
00048     if(find(referencingImages.begin(),referencingImages.end(),image)==referencingImages.end())
00049     {
00050         ThrowError("SparseStructure3D::Dereference atempting to dereference unreferenced image");
00051     }
00052     referencingImages.erase(find(referencingImages.begin(),referencingImages.end(),image));
00053     if(autoDestroy && referencingImages.size()==0)
00054     {
00055         printf("SparseStructure3D::Dereference refCount reached zero, deleting %x.\n",(uint)this);
00056         suicideInProgress=true;
00057         delete this;return true;
00058     }
00059     return false;
00060 }
00061 
00062 const SparseStructure3D *
00063 SparseStructure3D::Find(string sname)
00064 {
00065     for(uint i=0;i<allreadyExisting.size();i++)
00066     {
00067         if(allreadyExisting[i]->name==sname)
00068         {
00069             printf("SparseStructure3D::Find found \"%s\" in allreadyExisting (%x)\n",
00070                    sname.c_str(),(uint)allreadyExisting[i]);
00071             return allreadyExisting[i];
00072         }
00073     }
00074     printf("SparseStructure3D::CreateShared did not find \"%s\" in allreadyExisting\n",sname.c_str());
00075     return NULL;
00076 }
00077 
00078 
00079 
00080 SparseStructure3D:: ~SparseStructure3D()
00081 {
00082     if(autoDestroy && !suicideInProgress)
00083     {
00084         ThrowError("SparseStructure3D::~SparseStructure3D: trying to kill a SparseStructure3D that manages its own destruction");
00085     }
00086     allreadyExisting.erase(find(allreadyExisting.begin(),allreadyExisting.end(),this));
00087     if(referencingImages.size()>0)
00088     {
00089         printf("SparseStructure3D::~SparseStructure3D deleting %x with refCount==%d. I will invalidate all referencingImages\n",(uint)this,referencingImages.size());
00090         for(uint i=0;i<referencingImages.size();i++)
00091         {
00092             referencingImages[i]->Invalidate();
00093         }
00094     }
00095 }
00096 
00097 SparseStructure3D *SparseStructure3D::Create(const string &name)
00098 {
00099     SparseStructure3D *res=new SparseStructure3D();
00100     res->ReadFromFile(name);
00101     res->ComputeValSize();
00102     return res;
00103 }
00104 SparseStructure3D *SparseStructure3D::Create(ImLib3DFile *file,xmlpp::Element *parentNode,xmlpp::Element *node)
00105 {
00106     SparseStructure3D *res=new SparseStructure3D();
00107     res->Read(file,parentNode,node);
00108     res->ComputeValSize();
00109     return res;
00110 }
00111 SparseStructure3D *SparseStructure3D::Create(const BitMask3D &_mask,bool _autoDestroy)
00112 {
00113     return new SparseStructure3D(_mask,_autoDestroy);
00114 }
00115 
00116 SparseStructure3D::SparseStructure3D():
00117     size(-1),
00118     autoDestroy(false),//refCount(0),
00119     suicideInProgress(false),
00120     valNbToPosOk(false),posToValNbOk(false)
00121 {
00122     allreadyExisting.push_back(this);
00123 }
00124 SparseStructure3D::SparseStructure3D(BitMask3D _mask,bool _autoDestroy,int _size) :
00125     size(_size),mask(_mask),
00126     autoDestroy(_autoDestroy),//refCount(0),
00127     suicideInProgress(false),
00128     valNbToPosOk(false),posToValNbOk(false)
00129 {
00130     allreadyExisting.push_back(this);
00131     // compute size if not set (-1)
00132     if(size<0){ComputeValSize();}
00133 }

Generated on Fri Jun 17 13:36:07 2005 for ImLib3D by  doxygen 1.4.2