creaImageIOTreeDescriptor
creaImageIOTreeLevelDescriptor
creaImageIOTreeAttributeDescriptor
- creaImageIOTreeComparators
+
# Image readers
creaImageIOAbstractImageReader
AbstractImageReader() {}
virtual ~AbstractImageReader() {}
+ /// Get the reader's name
const std::string& GetName() const { return mName; }
+
+ /// Add file extensions read by the reader
virtual void PushBackExtensions(std::vector<std::string>&) {}
+
+ /// Test if file is read by this reader
virtual bool CanRead(const std::string& filename) { return false; }
+
+ /// return for a file a 2D VTkImage
virtual vtkImageData* ReadImage(const std::string& filename) { return 0; }
+
+ /// Read the attributes for a file
virtual void ReadAttributes(const std::string& filename,
tree::AttributeMapType& attr) {}
protected:
+
+ /// Set the reader's name
void SetName(const std::string& s) { mName = s; }
private:
std::string mName;
//=====================================================================
bool DicomImageReader::CanRead(const std::string& filename)
{
- // std::cout << "## Reader "<<GetName()
- //<<" ::CanRead("<<filename<<")"
- // <<std::endl;
- // return true;
-
-
- // GDCM_NAME_SPACE
- // std::cout << "GDCM_NAME_SPACE = '" << STRINGIFY_SYMBOL(GDCM_NAME_SPACE)
- // << "'"
- // <<std::endl;
GDCM_NAME_SPACE::Document*doc;
GDCM_NAME_SPACE::File* file = GDCM_NAME_SPACE::File::New();
//=====================================================================
vtkImageData* DicomImageReader::ReadImage(const std::string& filename)
{
- // std::cout << "## Reader "<<GetName()
- //<<" ::Read("<<filename<<")"
- // <<std::endl;
vtkImageData* im = 0;
try
void DicomImageReader::ReadAttributes(const std::string& filename,
std::map<std::string,std::string>& attr)
{
- // std::cout << "DicomImageReader::ReadDicomInfo '"<<filename<<"'"<<std::endl;
+
GimmickMessage(2,"Reading attributes from DICOM file '"
<<filename<<"'"<<std::endl);
uint16_t gr;
uint16_t el;
tree::AttributeDescriptor::GetDicomGroupElementFromKey(i->first,gr,el);
- // GimmickMessage(2,"Key '"<<i->first<<"' : "<<gr<<"|"<<el
- // <<std::endl);
if ( ( gr!=0 ) && ( el!=0 ) )
{
std::string val = file->GetEntryString(gr,el);
i->second = irclean(val);
- // GimmickMessage(2,"Key '"<<i->first<<"' : "<<gr<<"|"<<el
- // <<"="<<i->second<<std::endl);
}
}
}
DicomImageReader();
virtual ~DicomImageReader();
+ /// Add file extensions read by the reader
virtual void PushBackExtensions(std::vector<std::string>&);
+ /// Test if file is read by this reader
virtual bool CanRead(const std::string& filename);
- virtual vtkImageData* ReadImage(const std::string& filename);
+ /// return for a file a 2D VTkImage
+ virtual vtkImageData* ReadImage(const std::string& filename);
+ /// Read the attributes for a file
virtual void ReadAttributes(const std::string& filename,
tree::AttributeMapType& attr);
const std::string &i_locDesc,
const std::string &i_locDB);
- // add an existent DB
+ /// add an existent DB
void addDB(const std::string &i_nameDB, const std::string &i_locationDB);
/// Returns the TreeHandler with a given name
//=====================================================================
- /*
-
-
-
-
-
-
-
-
- //====================================================================
- // General
- //====================================================================
-
- /// Returns the size of the current selection
- virtual int GetSelectionSize() { return 0; }
- /// Returns true if there is a valid selection
- virtual bool IsSelectionValid(){ return false; }
- /// Returns the vector of full filenames of selected images
- virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
- /// Returns the vector of images corresponding to selection
- virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
- /// Returns the vector of DicomNode corresponding to selection
- virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
- /// Returns the DicomNode corresponding to the tree item
- virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
-
-
- /// Type of list of DicomDatabase
- typedef std::vector<DicomDatabase*> DicomDatabaseListType;
- /// Returns the list of DicomDatabase open
- virtual DicomDatabaseListType& GetDicomDatabaseList()
- { return null; }
- /// Returns the list of DicomDatabase open (const)
- virtual const DicomDatabaseListType& GetDicomDatabaseList() const
- { return null; }
-
- protected:
- ///Opens an existing database, or else, creates a local database.
- virtual void OpenOrNewDatabase(bool open){ return; }
- ///Shows the help
- virtual void ShowHelp();
-
- private:
- ///Gets the extension of the database
- const std::string& GetDatabaseExtension() { return null; }
- ///Sets the extension of the database
- virtual void SetDatabaseExtension(const std::string& ext){ return; }
-
-
- //====================================================================
- // Preview Display Related
- //====================================================================
-
-
- ///Shows the image sent as a parameter
- private:
- virtual void ShowImage(vtkImageData* image){ return; }
-
- //====================================================================
- // Favorites Related
- //====================================================================
-
-
- public:
- ///Loads or creates a favorites database
- virtual void LoadOrCreateFavoritesDatabase(){ return; }
- private:
- ///Creates the user settings directory
- void CreateUserSettingsDirectory(){ return; }
- ///Obtains the user settings directory
- const std::string& GetUserSettingsDirectory(){ return null; }
-
- //====================================================================
- // Attribute Display Related
- //====================================================================
-
-
- ///Shows the Information regarding the node sent as a parameter
- private:
- virtual void ShowInformation(DicomNode*){ return; }
-
- //====================================================================
- // Tree Display Related
- //====================================================================
-
- protected:
- /// Completely rebuilds the view with
- /// current DicomDatabaseList
- virtual void RebuildView(){ return; }
- /// Recursively updates the part of the view corresponding
- /// to the DicomDatabase passed
- /// i.e. creates items for the DicomNode which do not have
- /// deletes obsolete items (whose DicomNode has been deleted)
- virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
- /// Recursively updates the part of the view corresponding
- /// to the DicomNode provided.
- /// parent is its parent in the tree (where to insert / remove it)
- virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
-
- private:
- ///Type definition of the data regarding the tree
- typedef WxGimmickTreeItemData TreeItemData;
- ///Gets the item data of the tree item passed as a parameter
- TreeItemData* GetItemData(const TreeItemId& id){ return null; }
- ///Type definition of the data insid a node of the tree
- typedef WxGimmickDicomNodeData NodeData;
-
-
- //====================================================================
- // Class Attributes
- //====================================================================
-
-
- int mSelectionType;
- int mSelectionMaxImageDimension;
- int mCurrentSelectionImageSize[4];
-
- ///Existent Database List
- DicomDatabaseListType mDicomDatabaseList;
- ///Favorites database
- DicomDatabase* mFavoriteDatabase;
-
- ///Path to the database list file
- std::string mDatabaseListFile;
- ///Extension of the database
- std::string mDatabaseExtension;
-
- bool mJustStarted;
-
- int mFirstDicomDatabaseIconIndex;
-
- // Previewer
- vtkImageViewer2* mViewer;
-
- int mx1,mx2,my1,my2,mz1,mz2;
- double mspx,mspy,mspz;
-
- // Image preview :
- // Multi-thread image reader
- MultiThreadImageReader mReader;
- // map of images name to node
- std::map<std::string,DicomNode*> mImageFileNameToNode;
- */
+
} // EO namespace creaImageIO
Register(new DicomImageReader);
Register(new UltrasonixImageReader);
- /*
- std::cout << "## Registered file extensions : "<<std::endl;
- std::vector<std::string>::const_iterator i;
- for (i=GetKnownExtensions().begin();
- i!=GetKnownExtensions().end();
- i++)
- {
- std::cout << "'"<<(*i)<<"'"<<std::endl;
- }
- */
- //
+
mUnreadableImage = vtkImageData::New();
int dim[3];
dim[0] = dim[1] = 128;
//=====================================================================
ImageReader::~ImageReader()
{
- // std::cout << "#### ImageReader::~ImageReader()"<<std::endl;
- std::vector<AbstractImageReader*>::iterator i;
+ std::vector<AbstractImageReader*>::iterator i;
for (i=mReader.begin(); i!=mReader.end(); i++)
{
- // std::cout << "#### ImageReader::UnRegister("
- // << (*i)->GetName()<<")"<<std::endl;
delete (*i);
}
mReader.clear();
//=====================================================================
void ImageReader::Register(AbstractImageReader* r)
{
- // std::cout << "#### ImageReader::Register("<<r->GetName()<<")"<<std::endl;
mReader.push_back(r);
- // r->PushBackExtensions(mKnownExtensions);
+
}
//=====================================================================
//=====================================================================
// Returns true iff the file is readable
bool ImageReader::CanRead( const std::string& filename )
- // const std::string& exclude )
{
- // std::cout << "## ImageReader::CanRead("<<filename<<")"<<std::endl;
bool ok = false;
std::vector<AbstractImageReader*>::iterator i;
for (i=mReader.begin(); i!=mReader.end(); i++)
{
- // if ((*i)->GetName()==exclude) continue;
ok = (*i)->CanRead(filename);
if (ok)
{
//=====================================================================
// Reads the file (CanRead must be called before : no test here)
vtkImageData* ImageReader::ReadImage( const std::string& filename)
- // const std::string& exclude )
{
- // std::cout << "## ImageReader::Read("<<filename<<")"<<std::endl;
if (mLastFilename!=filename)
{
- if (!CanRead(filename)) //,exclude))
+ if (!CanRead(filename))
{
- // std::cout << " -- Cannot read image "<<std::endl;
vtkImageData* im = vtkImageData::New();
im->ShallowCopy(mUnreadableImage);
return im;
}
}
vtkImageData* i = mLastReader->ReadImage(mLastFilename);
- // std::cout << "i="<<i<<std::endl;
if (i==0)
{
- // std::cout << "i=UNREAD"<<i<<std::endl;
i = vtkImageData::New();
i->ShallowCopy(mUnreadableImage);
}
- // std::cout << "i="<<i<<std::endl;
- //std::cout<<"return: "<<i->GetScalarTypeAsString()<<", pointer="<<i<<std::endl;
return i;
}
//=====================================================================
void ImageReader::ReadAttributes(const std::string& filename,
std::map<std::string,std::string>& attr)
{
- // std::cout << "ImageReader::ReadDicomInfo '"<<filename<<"'"<<std::endl;
- // std::cout << "## ImageReader::Read("<<filename<<")"<<std::endl;
if (mLastFilename!=filename)
{
if (!CanRead(filename))
protected:
+ /// Register a reader
void Register(AbstractImageReader*);
std::vector<AbstractImageReader*> mReader;
#include <creaImageIOSystem.h>
#include <stdio.h>
#include <time.h>
-
+#include <wx/thread.h>
// Signal/slot mechanism
#include <boost/signal.hpp>
#include <boost/bind.hpp>
vtkImageData* image)
{
wxMutexLocker lock(mMultiThreadImageReaderUserMutex);
+
this->OnMultiThreadImageReaderEvent(filename,type,image);
}
//=====================================================================
{
ThreadedImageReader* t = new ThreadedImageReader(this);
mThreadedImageReaderList.push_back(t);
+ std::cout << " ===> Thread "<<i
+ <<" successfully added"<< std::endl;
}
mNumberOfThreadedReadersRunning = 0;
// Init the queue
}
else
{
- // std::cout << " ===> Thread "<<(*i)->GetCurrentId()
- // <<" successfully created"<< std::endl;
+ std::cout << " ===> Thread "<<(*i)->GetCurrentId()
+ <<" successfully created"<< std::endl;
}
}
for (i =mThreadedImageReaderList.begin();
i!=mThreadedImageReaderList.end();
i++)
- {
+ { std::cout << " ===> Thread "<<(*i)->GetCurrentId()
+ <<" successfully stopped"<< std::endl;
if((*i)->IsAlive())
{
(*i)->Delete();
do
{
// Sleep a little
- wxMilliSleep(10);
+ wxMilliSleep(10);
// Lock
{
wxMutexLocker locker(GetMultiThreadImageReaderUserMutex());
}
else if (e==MultiThreadImageReaderUser::ThreadedReaderStopped)
{
- mNumberOfThreadedReadersRunning--;
+
+ mNumberOfThreadedReadersRunning--;
// std::cout << "#TR=" << mNumberOfThreadedReadersRunning << std::endl;
}
}
// While was not deleted
while (!TestDestroy())
{
- // std::cout << "### Thread "<<GetCurrentId()<<" waiting for image"
- // << std::endl;
+ //std::cout << "### Thread "<<GetCurrentId()<<" still alive" << std::endl;
// Lock the mutex
mMultiThreadImageReader->MultiThreadImageReaderEventLock();
//=============================================================
- //=============================================================
- // void SQLiteTreeHandler::Print() const
- // {
- /*
- std::cout << "-> '"<<GetName()<< "' - '"
- << GetFileName()<<"'"<<std::endl;
- ChildrenListType::const_iterator i;
- for (i=GetChildrenList().begin(); i!=GetChildrenList().end(); i++)
- {
- (*i)->Print();
- }
- */
- // }
- //=============================================================
-
- //=====================================================================
- /*
- bool SQLiteTreeHandler::LocationIsValid()
- {
- // TO DO
- return true;
- }
- */
//=====================================================================
}
//=====================================================================
- // sqlite3_exec(db, zSQL, 0, 0, 0);
- // sqlite3_free(zSQL);
- // char* CHAIN = format_sql(QUER); \
-// sqlite3_free(CHAIN); \
-
+
//=====================================================================
#define QUERYDB(QUER,RES) \
try \
//=====================================================================
bool SQLiteTreeHandler::DBImportTreeDescription()
{
- GimmickMessage(1,"Importing tree description from database ..."
+ GimmickMessage(1,"Importing tree description for database ..."
<<std::endl);
// Test table 'LEVELS' existence
a!= GetTree().GetAttributeDescriptorList(0).end();
++a)
{
- /*
- std::string v;
- AttributeMapType::const_iterator i = attr.find(a->GetKey());
- if ( i != attr.end() )
- {
- v = i->second;
- }
- */
+
GetTree().UnsafeSetAttribute( a->GetKey(), "" );
}
}
//=====================================================================
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
//========================================================================
///
std::string& SQLformat(std::string& str)
{
continue;
}
- // std::cout << "("<<i->first<<","<<i->second<<")"<<std::endl;
+
atts += "'" + i->first + "'";
values += "'" + SQLformat(i->second) + "'";
atts += ",";
}
//=====================================================================
-
//=====================================================================
int SQLiteTreeHandler::DBLoadChildren(tree::Node* node,
int numberoflevels)
query += GetTree().GetLevelDescriptor(level+1).GetName();
if (level>0)
{
- query += " WHERE PARENT_ID='" + node->UnsafeGetAttribute("ID")
+ query += " WHERE PARENT_ID='" + node->GetAttribute("ID")
+ "'";
}
CppSQLite3Query q;
{
n->UnsafeSetAttribute(q.fieldName(fld),q.getStringField(fld));
}
- /*
- // Index
- TypeId ti;
- ti.type = type;
- ti.id = n->GetFieldValue("ID");
- mTypeIdToNodeMap[ti] = n;
- */
+
// recurse
if ( numberoflevels != 1 )
{
// Insert in DB
DBInsert(child);
- /*
- std::string val;
- SQLAppendAttributesValues(child,val);
- std::string insert("INSERT INTO ");
- insert += GetTree().GetLevelDescriptor(child->GetLevel()).GetName();
- insert += " " + val + ";";
- UPDATEDB(insert);
- // Store DB id of newly created node;
- long lastrow = mDB->lastRowId();
- std::stringstream ri;
- ri << mDB->lastRowId();
- child->SetAttribute("ID",ri.str());
- */
// Down one level
parent = child;
-
- /*
- // Insert in TypeId map
- TypeId ti;
- ti.type = node->GetType();
- ti.id = node_id;
- mTypeIdToNodeMap[ti] = node;
- // std::cout << "== Insert TypeId ("<<ti.type<<","<<ti.id<<")"<<std::endl;
- //
- msw[2].Pause();
-
- if (node->GetType()==Node::Patient) summary.added_patients++;
- if (node->GetType()==Node::Study) summary.added_studies++;
- if (node->GetType()==Node::Series) summary.added_series++;
- if (node->GetType()==Node::Image) summary.added_images++;
- */
- }
+ }
}
//======================================================================
query += GetTree().GetLevelDescriptor(level).GetName();
if (level>0)
{
- query += " WHERE ID='" + n->UnsafeGetAttribute("ID")
+ query += " WHERE ID='" + n->GetAttribute("ID")
+ "'";
}
CppSQLite3Query q;
UPDATEDB(out.str());
}
- /*
- //=====================================================================
- bool SQLiteTreeHandler::DBInsert(Node* alien_node,
- UpdateSummary& summary)
- {
- // std::cout << "SQLiteTreeHandler::Insert('"<<alien_node->GetLabel()
- // <<"')"<<std::endl;
-
- // if (!ChildrenLoaded()) DBLoadChildren(this,Node::Database);
-
- // Find parent
- Node* parent;
- std::string parent_id;
- parent = DBGetOrCreateParent(alien_node,parent_id,summary);
-
- // Insert
- DBRecursiveGetOrCreateNode(alien_node,parent,parent_id,summary);
- return true;
- }
- //=====================================================================
-
-
- //=====================================================================
- Node* SQLiteTreeHandler::DBGetOrCreateParent(Node* alien_node,
- std::string& parent_id,
- UpdateSummary& summary)
- {
- // std::cout << "DBGetOrCreateParent '" << alien_node->GetLabel()<<"'"
- // << std::endl;
- // Load the patients if not already done
- DBLoadChildren(this,Node::Patient);
-
- parent_id = "";
- Node* parent = this;
-
- // The chain of ancestors
- std::deque<Node*> chain;
- Node* cur = alien_node->GetParent();
- for (int type=Node::Patient;
- type<alien_node->GetType();++type)
- {
- chain.push_front(cur);
- cur = cur->GetParent();
- }
-
- // create the nodes if do not exist
- std::deque<Node*>::iterator i;
- for (i=chain.begin();i!=chain.end();++i)
- {
- // std::cout << " cur = '"<<(*i)->GetLabel()<<"'"<<std::endl;
- // std::string cur_id = DBGetNodeId(*i,parent_id);
- // if (cur_id.size()==0)
- // {
- // Node does not exist : create it
- std::string cur_id;
- parent = DBGetOrCreateNode(*i,
- parent,
- parent_id,
- cur_id,
- summary
- );
- DBLoadChildren(parent,parent->GetType()+1);
-
- parent_id = cur_id;
- }
- return parent;
- }
- //=====================================================================
-
-
-
- //=====================================================================
- void SQLiteTreeHandler::DBRecursiveGetOrCreateNode(Node* alien_node,
- Node* parent,
- const std::string& parent_id,
- UpdateSummary& summary)
- {
- // std::cout << "SQLiteTreeHandler::RecursiveGetOrCreateNode('"
- // <<alien_node->GetLabel()
- // <<"','"<<parent<<"','"<<parent_id<<"')"<<std::endl;
- if (parent != 0)
- {
- // std::cout << " -- Parent = '"<<parent->GetLabel()<<"'"<<std::endl;
- }
- std::string new_id;
- Node* new_node = DBGetOrCreateNode(alien_node,
- parent,
- parent_id,
- new_id,
- summary);
- Node::ChildrenListType::iterator i;
- for (i = alien_node->GetChildrenList().begin();
- i != alien_node->GetChildrenList().end();
- i++)
- {
- DBRecursiveGetOrCreateNode((*i),new_node,new_id,summary);
- }
- }
- //=====================================================================
-
-
- //=====================================================================
- Node* SQLiteTreeHandler::DBGetOrCreateNode(Node* alien_node,
- Node* internal_parent,
- std::string parent_id,
- std::string& node_id,
- UpdateSummary& summary)
- {
- // std::cout << "DBGetOrCreateNode('"<<alien_node->GetLabel()<<"','"
- // << internal_parent << "','"<< parent_id<<"')"<<std::endl;
- if (internal_parent != 0)
- {
- // std::cout << " -- Parent = '"<<internal_parent->GetLabel()<<"'"<<std::endl;
- }
- // Node Exists ? return it
- // First try among children of internal parent
- Node* node = GetChildrenLike(internal_parent,alien_node);
- if (node>0)
- {
- node_id = node->UnsafeGetFieldValue("ID");
- return node;
- }
- // Second : try in DB
-
- // Does not exist : Create new one
- node = new Node(alien_node->GetType(),this,internal_parent);
- node->SetChildrenLoaded(true);
- // Copy fields values from alien
- Node::FieldValueMapType::iterator i,j;
- for (i = node->GetFieldValueMap().begin();
- i != node->GetFieldValueMap().end();
- i++)
- {
- j = alien_node->GetFieldValueMap().find(i->first);
- if (j != alien_node->GetFieldValueMap().end() )
- {
- i->second = j->second;
- }
- }
-
- msw[2].Resume();
- if (node->GetType()!=Node::Patient)
- node->SetFieldValue("PARENT_ID",parent_id);
-
- // Insert in DB
- std::string val;
- BuildSQLFieldsValues(node,val);
- std::string insert("INSERT INTO ");
- insert += std::string(SQLiteTreeHandlerStructure::Table(node->GetType()))
- + " " + val + ";";
- // std::cout << "** SQL = '"<<insert<<"'"<<std::endl;
- UPDATEDB(insert);
- // std::cout << "** SQL OK"<<std::endl;
-
- // Store DB id of newly created node;
- long lastrow = mDB->lastRowId();
- std::stringstream ri;
- ri << mDB->lastRowId();
- node_id = ri.str();
- // std::cout << "LastRowId='"<<mDB->lastRowId()<<"' vs '"<<created_id<<"'"<<std::endl;
-
- node->SetFieldValue("ID",node_id);
- // Insert in TypeId map
- TypeId ti;
- ti.type = node->GetType();
- ti.id = node_id;
- mTypeIdToNodeMap[ti] = node;
- // std::cout << "== Insert TypeId ("<<ti.type<<","<<ti.id<<")"<<std::endl;
- //
- msw[2].Pause();
-
- if (node->GetType()==Node::Patient) summary.added_patients++;
- if (node->GetType()==Node::Study) summary.added_studies++;
- if (node->GetType()==Node::Series) summary.added_series++;
- if (node->GetType()==Node::Image) summary.added_images++;
-
- return node;
- }
- //=====================================================================
-
- //=====================================================================
- Node* SQLiteTreeHandler::GetChildrenLike(Node* parent,
- Node* alien_node)
- {
- Node::ChildrenListType::iterator i;
- for (i = parent->GetChildrenList().begin();
- i != parent->GetChildrenList().end();
- i++)
- {
- Node::Type type = alien_node->GetType();
- bool ok = true;
- for (int j=0;
- j<SQLiteTreeHandlerStructure::NbQueryFields(type);
- j++)
- {
- if (
- alien_node->GetFieldValue(SQLiteTreeHandlerStructure::
- QueryField(type,j).key ) !=
- (*i)->GetFieldValue(SQLiteTreeHandlerStructure::
- QueryField(type,j).key ) )
- {
- ok = false;
- break;
- }
- }
- if (ok)
- {
- return (*i);
- }
- }
- return 0;
- }
- //=====================================================================
-
- //=====================================================================
- std::string SQLiteTreeHandler::DBGetNodeId(Node* node,
- const std::string& parent_id)
- {
- // std::cout << "SQLiteTreeHandler::DBGetNodeId('"<<node->GetLabel()
- // <<"','"<<parent_id<<"')"
- // <<std::endl;
- msw[2].Resume();
- int type = node->GetType();
-
- std::string table = SQLiteTreeHandlerStructure::Table(type);
- std::string where = "WHERE ";
-
- if (type!=Node::Patient)
- {
- where += "PARENT_ID='" + parent_id
- //node->GetFieldValue("PARENT_ID")
- + "' AND ";
- }
-
- for (int i=0;i<SQLiteTreeHandlerStructure::NbQueryFields(type);i++)
- {
- where += SQLiteTreeHandlerStructure::QueryField(type,i).key + "='"
- + node->GetFieldValue(SQLiteTreeHandlerStructure::QueryField(type,i).key) + "' ";
- if (i<SQLiteTreeHandlerStructure::NbQueryFields(type)-1)
- where += "AND ";
- }
-
- std::string query = "SELECT ID FROM " + table + " " + where + ";";
- // std::cout << "** SQL = '"<<query<<"'"<<std::endl;
- CppSQLite3Query q;
- QUERYDB(query,q);
-
- if (!q.eof())
- {
-
- // std::cout << " - Node exists " << std::endl;
- std::string id = q.getStringField(0);
- // std::cout << " id = '"<<id<<"'"<<std::endl;
- msw[2].Pause();
- return id;
- }
- msw[2].Pause();
- return "";
- }
- //=====================================================================
-
-
-
- //=====================================================================
- Node* SQLiteTreeHandler::GetNodeFromTypeId(Node::Type type,
- const std::string& id)
- {
- // std::cout << "GetNodeFromTypeId("<<type<<","<<id<<")"<<std::endl;
-
- TypeId ti;
- ti.type = type;
- ti.id = id;
-
- TypeIdToNodeMapType::iterator i = mTypeIdToNodeMap.find(ti);
- if (i == mTypeIdToNodeMap.end())
- {
-
- std::cout << "Internal error : mTypeIdToNodeMap does not contain key"
- << std::endl;
- creaError("Internal error : mTypeIdToNodeMap does not contain key");
- // }
- }
-
- // std::cout << " ** Node = "<<i->second<<std::endl;
- return i->second;
- }
-
- //=====================================================================
-
- //=====================================================================
- bool SQLiteTreeHandler::Remove(Node* node)
- {
-
- //DBRecursiveRemoveNode(node);
-
- // std::cout << "DELETE"<<std::endl;
- if (node->GetParent())
- {
- node->GetParent()->RemoveChildrenFromList(node);
- }
- delete node;
- // std::cout << "DELETE OK"<<std::endl;
- return true;
- }
-
-
- //========================================================================
-
- //=====================================================================
- void SQLiteTreeHandler::DBRecursiveRemoveNode(Node* node)
- {
- // std::cout << "SQLiteTreeHandler::DBRecursiveRemoveNode('"
- // <<node->GetLabel()<<"')"<<std::endl;
-
- std::string query = "DELETE FROM ";
- query += SQLiteTreeHandlerStructure::Table(node->GetType());
- query += " WHERE ID='"+ node->GetFieldValue("ID") + "';";
-
- UPDATEDB(query);
-
- Node::ChildrenListType::iterator i;
- for (i = node->GetChildrenList().begin();
- i != node->GetChildrenList().end();
- i++)
- {
- DBRecursiveRemoveNode((*i));
- }
- }
-
- //=====================================================================
-
- //=====================================================================
- int SQLiteTreeHandler::DBQueryNumberOfChildren(Node* node)
- {
- std::string query = "SELECT COUNT (ID) FROM ";
- query += SQLiteTreeHandlerStructure::Table(node->GetType()+1);
- if (node->GetType() != Node::Database)
- {
- query += " WHERE PARENT_ID='"+ node->GetFieldValue("ID")+"'";
- }
- query += ";";
-
- // std::cout << "**SQL = "<< query << std::endl;
-
- CppSQLite3Query q;
- QUERYDB(query,q);
-
- // std::cout << "**RES = "<< q.getIntField(0) <<std::endl;
-
- return q.getIntField(0);
- }
- //=====================================================================
-
-
-
-*/
-
-
-
} // namespace creaImageIO
//======================================================================
- /*
- ///
- int DBQueryNumberOfChildren(tree::Node* n);
-
- // Insertion
- bool DBInsert(tree::Node* alien_node) ; //, UpdateSummary& summary);
-
- //
- std::string DBGetNodeId(tree::Node* node, const std::string& parent_id);
-
- tree::Node* GetNodeFromTypeId(int level,
- const std::string& id);
-
- //
- tree::Node* DBGetOrCreateNode(tree::Node* alien_node,
- tree::Node* internal_parent,
- std::string parentid,
- std::string& created_id);
- // UpdateSummary& summary);
-
- tree::Node* DBGetOrCreateParent(tree::Node* alien_node,
- std::string& parent_id);
- // UpdateSummary& summary);
-
- void DBRecursiveGetOrCreateNode(tree::Node* alien_node,
- tree::Node* parent,
- const std::string& parent_id);
- // UpdateSummary& summary);
-
-
- */
-
- /*
-
- void BuildSQLFieldsValues(tree::Node* n,
- std::string& str);
-
-
- tree::Node* GetChildrenLike(tree::Node* internal_parent,
- tree::Node* alien_node);
- */
+
private:
/// The DB
CppSQLite3DB* mDB;
bool GetWritable() const { return mWritable; }
bool mIsAdding;
- /*
- struct TypeId
- {
- int type;
- std::string id;
- bool operator< (const TypeId& o) const
- {
- return ((type<o.type) ||
- ((type==o.type)&&id<o.id));
- }
- };
-
- typedef std::map<TypeId,tree::Node*> TypeIdToNodeMapType;
- TypeIdToNodeMapType mTypeIdToNodeMap;
- */
+
};
// EO class SQLiteTreeHandler
//=======================================================================
{
// Numerical
typ = 1;
-// type="1";
-// sscanf(type.c_str(),"%u",&typ);
}
else
{
// String
typ = 2;
- // type="2";
-// sscanf(type.c_str(),"%u",&typ);
}
}
///Decodes the type of attribute into the existing ones
void DecodeType(unsigned int& type) const;
+ /// Determines if Attribute is a date
bool isDateEntry() const;
+
+ /// Determines if Attribute is a time
bool isTimeEntry() const;
private:
const unsigned int AttributeDescriptor::IDENTIFIER = 2;
/// The attribute can be edited
const unsigned int AttributeDescriptor::EDITABLE = 3;
+ /// the attribute describes the node
const unsigned int AttributeDescriptor::LABEL = 4;
//==================================================================
std::string databaseVal;
mTreeHandler->GetAttribute("Image","FullFileName",file,a->GetKey(),databaseVal);
std::string fileVal=attr.find(a->GetKey())->second;
- if ( a->GetFlags()==0 && databaseVal.compare(fileVal)!=0 )
+ if ( a->GetFlags()==0 && databaseVal == fileVal)
{
if(repair)
{
/// Remove the given children from the children list
int RemoveChildrenFromList(Node*);
-
+
+ /// Get the Attributes Map
AttributeMapType& GetAttributeMap() { return mAttributeMap; }
+
+ /// Get the Attributes Map
const AttributeMapType& GetAttributeMap() const { return mAttributeMap; }
+
+ /// Get the Attribute for a specific key
const std::string& GetAttribute(const std::string& k) const;
- const std::string& GetCleanAttribute(const std::string& k) const;
- const std::string& UnsafeGetAttribute(const std::string& k) const
- { return mAttributeMap.find(k)->second; }
+
+ /// Get the Attribute for a specific key without OS dependance (not implemented)
+ // TODO : backslash OS uniformity
+ const std::string& GetCleanAttribute(const std::string& k) const;
+
+ /// Set an Attribute for a specific key
void SetAttribute(const std::string& k, const std::string& v);
+
+ /// Set an Attribute for a specific key(unsafe mode)
void UnsafeSetAttribute(const std::string& k, const std::string& v)
{ mAttributeMap[k] = v; }
+ /// Get Descriptor for an Attribute
const AttributeDescriptor& GetAttributeDescriptor(const std::string& k)const;
- // { return GetTypeDescription().GetFieldDescription(k); }
-
-
- /// Returns true iff the KEY attributes of the node match those of the map provided
+
+ /// Returns true if the KEY attributes of the node match those of the map provided
bool Matches( const AttributeMapType& ) const;
/// Returns the node data casted into the type T
/// Sorts the children of the node
void SortChildren(const LexicographicalComparator&);
+ /// Print the node
virtual void Print() const;
+
+ /// Get the Label of the node
std::string GetLabel() const;
- /*
- int ImageGetRows() const;
- int ImageGetColumns() const;
- int ImageGetFrames() const;
- const std::string& ImageGetFullFileName() const { return UnsafeGetAttribute("FullFileName"); }
- */
+
private:
/// The parent of the node
void UltrasonixImageReader::ReadAttributes(const std::string& filename,
std::map<std::string,std::string>& attr)
{
- // std::cout << "UltrasonixImageReader::ReadDicomInfo '"<<filename<<"'"<<std::endl;
GimmickMessage(2,"Reading attributes from '"<<filename<<std::endl);
-
FILE *Ultrasonix_file=fopen(filename.c_str(),"rb");
if (!Ultrasonix_file) return;
std::map<std::string,std::string>::iterator i;
if ( (i = attr.find("FullFileName")) != attr.end())
{
- // boost::filesystem::path full_path(filename);
- // std::string f = full_path.leaf();
i->second = filename;
}
if ( (i = attr.find("D0004_1500")) != attr.end())
UltrasonixImageReader();
virtual ~UltrasonixImageReader();
-
+ /// Add file extensions read by the reader
virtual void PushBackExtensions(std::vector<std::string>&);
+ /// Test if file is read by this reader
virtual bool CanRead(const std::string& filename);
+ /// return for a file a 2D VTkImage
virtual vtkImageData* ReadImage(const std::string& filename);
+ /// Read the attributes for a file
virtual void ReadAttributes(const std::string& filename,
tree::AttributeMapType& attr);
+
};
//=====================================================================
//=====================================================================
bool VtkImageReader::CanRead(const std::string& filename)
{
- // std::cout << "## Reader "<<GetName()
- //<<" ::CanRead("<<filename<<")"
- // <<std::endl;
return (mReader->CanReadFile(filename.c_str())!=0);
}
//=====================================================================
//=====================================================================
vtkImageData* VtkImageReader::ReadImage(const std::string& filename)
{
- // std::cout << "## Reader "<<GetName()
- //<<" ::Read("<<filename<<")"
- // <<std::endl;
vtkImageData* im = 0;
try
{
void VtkImageReader::ReadAttributes(const std::string& filename,
std::map<std::string,std::string>& attr)
{
- // std::cout << "VtkImageReader::ReadDicomInfo '"<<filename<<"'"<<std::endl;
GimmickMessage(2,"Reading attributes from '"<<filename<<std::endl);
// Get image dimensions
// How to get the image info without loading it in vtk ?
// Planes
char planes[128];
sprintf(planes,"%i",ext[5]-ext[4]);
-
-
- //
- std::map<std::string,std::string>::iterator i;
+
+ std::map<std::string,std::string>::iterator i;
if ( (i = attr.find("FullFileName")) != attr.end())
{
- // boost::filesystem::path full_path(filename);
- // std::string f = full_path.leaf();
i->second = filename;
}
if ( (i = attr.find("D0004_1500")) != attr.end())
if ( (i = attr.find("D0028_0012")) != attr.end())
{
- i->second = planes;
+ i->second = planes;
}
if ( (i = attr.find("FullFileDirectory")) != attr.end())
{
virtual ~VtkImageReader();
+ /// Add file extensions read by the reader
virtual void PushBackExtensions(std::vector<std::string>&);
+ /// Test if file is read by this reader
virtual bool CanRead(const std::string& filename);
+ /// return for a file a 2D VTkImage
virtual vtkImageData* ReadImage(const std::string& filename);
+ /// Read the attributes for a file
virtual void ReadAttributes(const std::string& filename,
tree::AttributeMapType& attr);
{}
void* Entry();
- // void SetImagesToPlay(std::vector<vtkImageData*> im);
- // void ShowImage(vtkImageData* v);
- // void StartIterator();
void OnExit();
private:
- //std::vector<vtkImageData*> mImagesToPlay;
- //vtkImageViewer2* mViewer;
- /// Associated wxvtk interactor
- //crea::creawxVTKRenderWindowInteractor *mInteractor;
- //std::vector<vtkImageData*>::iterator i;
+
WxViewer* mWxViewer;
-
- // int mx1,mx2,my1,my2,mz1,mz2;
- // double mspx,mspy,mspz;
};
//=====================================================================