namespace creaImageIO
{
+ ///Class used to represent the actual state of the image selected and to perform comparisons on its values
+ class ImageExtent
+ {
+ public:
+ ImageExtent(const std::string& x, const std::string& y, const std::string& z, const std::string& t)
+ {
+ sscanf(x.c_str(),"%d",&mExtent[0]);
+ sscanf(y.c_str(),"%d",&mExtent[1]);
+ sscanf(z.c_str(),"%d",&mExtent[2]);
+ sscanf(t.c_str(),"%d",&mExtent[3]);
+ if(x==""){mExtent[0]=1;}
+ if(y==""){mExtent[1]=1;}
+ if(z==""){mExtent[2]=1;}
+ if(t==""){mExtent[3]=1;}
+
+ if (mExtent[3]>1) mDim=4;
+ else if (mExtent[2]>1) mDim=3;
+ else if (mExtent[1]>1) mDim=2;
+ else if (mExtent[0]>1) mDim=1;
+ else mDim=0;
+ }
+
+
+ ///Clears the extent
+ void Clear() { mExtent[0] = mExtent[1] = mExtent[2] = mExtent[3] = 1; }
+
+ ///Returns true if the two extents are compatible
+ bool IsCompatible( const ImageExtent& );
+
+ ///Adds the extent passed as a parameter to the current extent
+ void Add ( const ImageExtent& );
+
+ ///Returns the ieth position of the extent
+ int Get(int i) { return mExtent[i]; }
+
+ ///Returns the dimension of the current image
+ void SetDimension(int dim) { mDim=dim; }
+
+ ///Returns the dimension of the current image
+ int GetDimension() { return mDim; }
+
+ private:
+ int mExtent[4];
+ int mDim;
+ };
+
+ //======================================================================
+
//======================================================================
// CTor
GimmickView::GimmickView(Gimmick* gimmick, int threads)
// Anciently started the threads ...
// Threads now automatically start at first image request
//mReader.Start();
-
+
}
//======================================================================
///
void GimmickView::Initialize()
{
- row="";
- col="";
- plane="";
- selectionSize=0;
+ mImageExtent=0;
}
//======================================================================
}
//======================================================================
/// Clears the status and begins a new selection process
- void GimmickView::ClearStatus()
+ void GimmickView::ResetExtent()
{
- row="";
- col="";
- plane="";
- selectionSize=0;
+ if(mImageExtent!=0)
+ {
+ mImageExtent=0;
+ }
valid=true;
}
- class ImageExtent
+ //======================================================================
+
+ //======================================================================
+ bool ImageExtent::IsCompatible(const ImageExtent& ie)
{
- public:
- ImageExtent(const std::string& x, const std::string& y, const std::string& z, const std::string& t);
-
- void Clear() { mExtent[0] = mExtent[1] = mExtent[2] = mExtent[3] = 1; }
-
- bool IsCompatible( const ImageExtent& );
-
- void Add ( const ImageExtent& );
-
- int Get(int i) { return mExtent[i]; }
-
- int GetDimension() { return mDim; }
-
- private:
- int mExtent[4];
- int mDim;
- };
+ bool compatible=true;
+ ImageExtent * extent= (ImageExtent*)&ie;
+ if((*extent).Get(0)!=Get(0)
+ || (*extent).Get(1)!=Get(1))
+ {
+ compatible=false;
+ }
+ return compatible;
+ }
+ //======================================================================
+
+ //======================================================================
+ void ImageExtent::Add(const ImageExtent& ie)
+ {
+ ImageExtent * extent= (ImageExtent*)&ie;
+ mExtent[2]+=(*extent).Get(2);
+ SetDimension(3);
+ }
//======================================================================
///Validates the dimension compliance of the images with the maximum and
///minimum given, and between their sizes
bool GimmickView::ValidateSelected (tree::Node* sel, int min_dim, int max_dim)
{
- GimmickMessage(2,"Validating selected"<<std::endl);
+ GimmickDebugMessage(2,"Validating selected"<<std::endl);
std::string mMessage;
+
if(sel==0)
{
mMessage="Cannot have 0 images selected!";
valid=false;
}
- if(valid)
+ else
{
- selectionSize++;
- /*// EED validate all
- mValidationSignal(valid);
- return valid;*/
-
- int level;
-
-
- if(row.compare("")==0 || col.compare("")==0)
+ ImageExtent* ie=new ImageExtent((*sel).GetAttribute("D0028_0010"),
+ (*sel).GetAttribute("D0028_0011"),
+ (*sel).GetAttribute("D0028_0012"),
+ "");
+ if(mImageExtent==0)
{
- row=(*sel).GetAttribute("D0028_0010");
- col=(*sel).GetAttribute("D0028_0011");
- plane=(*sel).GetAttribute("D0028_0012");
- level=(*sel).GetLevel();
+ mImageExtent=ie;
+ if((mImageExtent->Get(min_dim-1)<2)||(mImageExtent->Get(max_dim)>1))
+ {
+ valid=false;
+ }
+ else
+ {
+ std::stringstream out;
+ out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
+ mMessage = out.str();
+ mImageExtent->SetDimension(2);
+ valid=true;
+ }
}
else
{
- if(((*sel).GetAttribute("D0028_0010"))!=row ||
- ((*sel).GetAttribute("D0028_0011"))!=col ||
- ((*sel).GetAttribute("D0028_0012"))!=plane)
+ if(mImageExtent->IsCompatible(*ie))
+ {
+ if(mImageExtent->GetDimension()==max_dim && mImageExtent->Get(max_dim)>2)
+ {
+ std::stringstream out;
+ out<<"Cannot add this image to selection : would result in a "<<mImageExtent->GetDimension()+1<<"D image!";
+ mMessage=out.str();
+ valid=false;
+ }
+ else if(max_dim<3)
+ {
+ std::stringstream out;
+ out<<"Selecting "<<mImageExtent->GetDimension()<<"D images is not allowed !";
+ mMessage=out.str();
+ valid=false;
+ }
+ else if(min_dim==3 && (ie->Get(2)+mImageExtent->Get(2))<2)
{
- mMessage="The selected images are not compatible.";
+ std::stringstream out;
+ out << "Cannot build the selection as it would result in a ";
+ out << mImageExtent->GetDimension();
+ out << "D image, and the minimum is ";
+ out << min_dim;
+ out << "D!";
+ mMessage=out.str();
valid=false;
}
+ else
+ {
+ mImageExtent->Add(*ie);
+ std::stringstream out;
+ out << mImageExtent->GetDimension() << "D image " << mImageExtent->Get(0) << "x"<< mImageExtent->Get(1) << "x"<< mImageExtent->Get(2) <<" selected";
+ mMessage = out.str();
+ }
+
+ }
+ else
+ {
+ mMessage="The selected images are not compatible.";
+ valid=false;
+ }
+ }
}
-
-
- int dim = 0;
- int rows;
- int cols;
- int planes;
-
- //Dimention validation
- //Compatibility with maximum and minimum
- if(valid)
- {
- sscanf(row.c_str(),"%d",&rows);
- sscanf(col.c_str(),"%d",&cols);
- sscanf(plane.c_str(),"%d",&planes);
- if(row==""){rows=1;}
- if(col==""){cols=1;}
- if(plane==""){planes=1;}
-
- std::cout << cols << "x"<<rows<<"x"<<planes << std::endl;
- if (planes>1) dim=3;
- else if (cols>1) dim=2;
- else if (rows>1) dim=1;
-
- if (dim == 0)
- {
- mMessage="Unknown image dimension : cannot select !";
- valid= false;
- }
- else if (dim>max_dim)
- {
- mMessage="Selecting ";
- mMessage+=dim;
- mMessage+="D images is not allowed !";
- valid= false;
- }
- if ( dim == max_dim )
- {
- mMessage="Cannot add this image to selection : would result in a ";
- mMessage+=(dim+1);
- mMessage+="D image!";
-
- valid= false;
- }
- if ( dim < min_dim )
- {
- GimmickMessage(1, "State Check: Dim: "
- <<dim
- <<" Dim min:"
- <<min_dim
- <<std::endl);
- std::stringstream out;
- out << "Cannot build the selection as it would result in a ";
- out << dim;
- out << "D image, and the minimum is ";
- out << min_dim;
- out << "D!";
- mMessage+=out.str();
- valid= false;
- }
- }
-
- if(valid)
- {
- std::stringstream out;
- out << dim << "D image " << cols << "x"<< rows << "x"<< planes <<" selected";
- mMessage = out.str();
- }
- }
mValidationSignal(valid);
SetMessage(mMessage);
return valid;
}
- //======================================================================
+//======================================================================
//======================================================================
///Reads Images (Non Threaded)
* \ingroup View
*/
-
+ class ImageExtent;
//=====================================================================
//=====================================================================
class GimmickView: public MultiThreadImageReaderUser
{
public:
-
/// Ctor
GimmickView(Gimmick*, int number_of_threads = 0 );
/// Virtual destructor
std::string GetMessage(){return mMess;}
///Obtains the message of the state
void SetMessage(std::string mess){mMess=mess;}
- ///Clears status and begins a new selection
- void ClearStatus();
+ ///Resets the data of the extent and begins a new selection
+ void ResetExtent();
/// Create the tree views
void CreateTreeViews();
private:
+
/// Controller which manages the interaction with the model
Gimmick* mGimmick;
/// The views
typedef std::deque<ImageEventType> ImageEventQueueType;
//ImageEventQueueType mImageEventQueue;
+ ImageExtent* mImageExtent;
ValidationSignalType mValidationSignal;
- std::string row;
- std::string col;
- std::string plane;
- int selectionSize;
bool valid;
};
{
tree::Node* parent = DBGetParent(attr);
DBGraftToParent(parent,attr);
+ int nChildren = GetNumberOfChildren(parent);
+ std::stringstream out;
+ out << nChildren;
+ if(parent->GetLevel()>0&&parent->GetLevel()<GetTree().GetNumberOfLevels())
+ {
+ DBSetAttribute(parent,"D1111_0011",out.str());
+ }
return (parent->GetLevel()+1);
}
//=====================================================================
<< i->GetGroup() << ","
<< i->GetElement() << ","
<< i->GetFlags() << ");";
-
UPDATEDB(insert.str());
}
}
}
- //=====================================================================
-
//=====================================================================
unsigned int SQLiteTreeHandler::GetNumberOfChildren(tree::Node* n)
{
//======================================================================
- // Recursively Removes the nodes whose parent is given as a parameter
+ /// Recursively Removes the nodes whose parent is given as a parameter
void DBRecursiveRemoveNode(tree::Node* node);
/*
///
// Patient level
Add(LevelDescriptor("Patient"));
+ Add(AttributeDescriptor(0x1111,0x0011, // Number of Series
+ AttributeDescriptor::LABEL),1);
Add(AttributeDescriptor(0x0010,0x0010, // Patient name
AttributeDescriptor::LABEL),1);
Add(AttributeDescriptor(0x0010,0x0040),1); // Patient sex
// Study-series level
Add(LevelDescriptor("Series"));
+ Add(AttributeDescriptor(0x1111,0x0011, // Number of Images
+ AttributeDescriptor::LABEL),2);
Add(AttributeDescriptor(0x0008,0x0060, // Modality
AttributeDescriptor::LABEL),2);
Add(AttributeDescriptor(0x0008,0x1030),2); // Study Description
}
else if(needProcess)
{
- ClearStatus();
+ ResetExtent();
std::vector<tree::Node*>::iterator i;
for(i=sel.begin();i!=sel.end()&&valid;++i)
{
}
else
{
- ClearStatus();
+ ResetExtent();
std::vector<tree::Node*>::iterator i;
for(i=sel.begin();i!=sel.end()&&valid;++i)
{
pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
mViewer->SetImageVector(pointers);
mViewer->RefreshIfNecessary();
- ClearStatus();
+ ResetExtent();
}
//=================================================
level.wxCtrl = ctrl;
level.wxSplitter->Initialize(ctrl);
- // Create the first column : number of children
- if(i<handler->GetTree().GetNumberOfLevels()-1)
- {
- std::string title = "#";
- if (i<handler->GetTree().GetNumberOfLevels()-1)
- {
- title += handler->GetTree().GetLevelDescriptor(i+1).GetName();
- if (title[title.size()-1]!='s')
- title += "s";
- }
- ctrl->InsertColumn(0,crea::std2wx(title),col_style);
- }
// Create the columns : one for each attribute of the level
- int col = 1;
+ int col = 0;
+ std::string title;
tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
for (a = handler->GetTree().GetAttributeDescriptorList(i).begin();
a != handler->GetTree().GetAttributeDescriptorList(i).end();
GimmickDebugMessage(5,"Creating column "<<col<<" : "
<<a->GetName()
<<std::endl);
+ if(a->GetName()=="UNKNOWN")
+ {
+ title = "#";
+ title += handler->GetTree().GetLevelDescriptor(i+1).GetName();
+ if (title[title.size()-1]!='s')
+ title += "s";
+
+ }
+ else
+ {
+ title=a->GetName();
+ }
ctrl->InsertColumn(col,
- crea::std2wx(a->GetName()),
+ crea::std2wx(title),
col_style);
level.key.push_back(a->GetKey());
// ctrl->SetColumnWidth(col, wxLIST_AUTOSIZE );
std::vector<tree::Node*>::iterator i;
- //Adds the first item (filter)
-
- for (i=sel.begin(); i!=sel.end(); ++i)
+ for (i=sel.begin(); i!=sel.end(); ++i)
{
GimmickDebugMessage(2,
"adding children of '"
<<std::endl);
int _id=1;
- //Adds items (other than the first) and sets their attributes
- GetCtrl(l)->InsertItem(0, _T(""));
+ //Adds items and sets their attributes
+ GetCtrl(l)->InsertItem(0, _T(""));
GetTreeHandler()->LoadChildren(*i,1);
tree::Node::ChildrenListType::reverse_iterator j;
for (j = (*i)->GetChildrenList().rbegin();
item->SetData(data);
_id++;
+ GetCtrl(l)->InsertItem(*item);
-
- //Setting first column (number of children)
- std::ostringstream oss;
- int n= 0; //GetTreeHandler()->GetNumberOfChildren(*j);
- oss << n;
- std::string s(oss.str());
- item->SetText( crea::std2wx(s));
-
- item->SetColumn(0);
- GetCtrl(l)->InsertItem(*item);
- //GetCtrl(l)->SetItem(item);
-
- //Setting other attributes
- if(level<mLevelList.size())
- {
- for (int k=1; k<GetCtrl(l)->GetColumnCount(); k++)
+ //Setting attributes
+
+ for (int k=0; k<GetCtrl(l)->GetColumnCount(); k++)
{
- std::string val = (*j)->GetAttribute(mLevelList[l].key[k-1]);
+ std::string val = (*j)->GetAttribute(mLevelList[l].key[k]);
if (val.size()==0) val = "?";
item->SetText( crea::std2wx(val));
item->SetColumn(k);
GetCtrl(l)->SetItem(*item);
- // Unefficient
- // GetCtrl(l)->RefreshItem(*item);
- }
- }
- else
- {
- for (int k=0; k<GetCtrl(l)->GetColumnCount(); k++)
- {
- std::string val = (*j)->GetAttribute(mLevelList[l].key[k]);
- if (val.size()==0) val = "?";
- item->SetText( crea::std2wx(val));
- item->SetColumn(k);
- GetCtrl(l)->SetItem(*item);
- // GetCtrl(l)->RefreshItem(*item);
}
- }
}
GetCtrl(l)->DeleteItem(0);
}
GetCtrl(l)->Show();
-
- // if (level<mLevelList.size()) UpdateLevel(level+1);
-
+
}
//=====================================================================
GimmickDebugMessage(1,
" Level "<<level+1
<<std::endl);
- /*
- if(event.m_itemIndex!=0)
- {*/
-
- if(level<mLevelList.size()-1)
- {
- //mSelected=GetSelected(level+1); //2);
- }
- else if(mProcess)
- {
- //mLastLevelSelected=GetSelected(level+1); //2);
- }
- else
- {
- event.Veto();
- }
// Update the children level (if selection not at last level)
if (level<mLevelList.size()-1)
ValidateSelectedImages (false);
}
}
- //SetColor(level,event.m_itemIndex);
- /*}
- else
- {
- if(event.GetEventType()==10145)
- {
-
- GetCtrl(level)->SetItemText(0,crea::std2wx(""));
- GetCtrl(level)->EditLabel(event.m_itemIndex);
- }
-
- }*/
-
}
//================================================================
{
long item = -1;
int level=mLevelList.size()-1;
-
for ( ;; )
{
item = GetCtrl(level)->GetNextItem(item,
{
mProcess=false;
}
-
- /*if(item!=0)
- {*/
GetCtrl(level)->SetItemState(item,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE
| wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
- //}
-
}
-
-
}
-
- //================================================================
- //================================================================
-
- void WxTreeView::OnMouseClick(wxMouseEvent& event)
- {
- if (event.ButtonDown())
- {
- }
- std::cout<<"HELLO WORLD"<<std::endl;
- }
//================================================================
//================================================================
{
if ( GetCtrl(level) == senderCtrl ) break;
}
- /*for(int i=0;i<mColumnSelected;i++)
- {
- clientpt.x+=GetCtrl(level)->GetColumnWidth(i);
- }
- for(int i=0;i<level;i++)
- {
- clientpt.x+=GetSplitter(i)->GetSashPosition();
- }
- clientpt.y+=level*2; */
- if(level==mLevelList.size()-1)
- {
- mColumnSelected+=1;
- PopupMenu(menu, clientpt);
- }
- else if(mColumnSelected!=0)
- {
- PopupMenu(menu, clientpt);
- }
+ PopupMenu(menu, clientpt);
}
- //================================================================
+
+ //================================================================
+ //================================================================
+
void WxTreeView::OnPopupFilter(wxCommandEvent& event)
{
wxBusyCursor busy;
long adr = GetCtrl(level)->GetItemData(it);
tree::Node* nod = ((ItemData*)adr)->node;
- att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
+ att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected]);
if(att.find(filter)>900)
{
//Obtain the column name and the level that needs to be organized
- if(level==mLevelList.size()-1||mColumnSelected!=0)
- {
int l = level - 1;
- //GetCtrl(level)->DeleteItem(0);
//Sets the data for the items to be sorted
std::string att;
unsigned int ty=0;
tree::Node* nod = ((ItemData*)adr)->node;
if(i==0)
{
- (*nod).GetAttributeDescriptor(mLevelList[level].key[mColumnSelected-1]).DecodeType(ty);
+ (*nod).GetAttributeDescriptor(mLevelList[level].key[mColumnSelected]).DecodeType(ty);
}
//Obtains the organizing attribute
- att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
+ att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected]);
char* d= new char [att.size()+1];
strcpy (d, att.c_str());
}
//Resets original data
+
std::vector<tree::Node*>::iterator selection;
std::vector<long> change;
long it = -1;
//Gets current item data, extracts the node and resets it
long item = GetCtrl(level)->GetItemData(it);
GetCtrl(level)->SetItemData(it,((long*)item)[0]);
- tree::Node* n= ((ItemData*)((long*)item)[0])->node;
- if(level<mLevelList.size()-1)
- {
- for(selection=mSelected.begin();selection!=mSelected.end();++selection)
- {
- if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0)
- {
- change.push_back(it);
- }
- }
- }
- else
- {
- for(selection=mLastLevelSelected.begin();selection!=mLastLevelSelected.end();++selection)
- {
- if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0)
- {
- change.push_back(it);
- }
- }
- }
-
+ tree::Node* n= ((ItemData*)((long*)item)[0])->node;
}
- //Resets the selected items
- std::vector<long>::iterator selectedIts;
- for(selectedIts=change.begin();selectedIts!=change.end();++selectedIts)
- {
- GetCtrl(level)->SetItemState(*selectedIts,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE
- | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
-
- }
- //GetCtrl(level)->InsertItem(0,_T("Filter:"));
- }
}
bool mDirection;
///The last selected item on the list
long mLastSelected;
- ///The last selection of nodes (for every level, except the last)
- std::vector<tree::Node*> mSelected;
- ///The last selection of nodes (for the last level)
- std::vector<tree::Node*> mLastLevelSelected;
///The color map
typedef std::map<tree::Node*,wxColour> ColorMap;
typedef std::pair<tree::Node*,wxColour> NodeColorPair;