#endif
wxInitAllImageHandlers();
- /*
+
creaImageIO::SetGimmickMessageLevel(9);
creaImageIO::SetGimmickDebugMessageLevel(9);
- */
+
int threads = 1;
MultiThreadImageReaderUser::EventType e,
vtkImageData* image)
{
+ GimmickDebugMessage(5,
+ "MultiThreadImageReader event : "<<e<<std::endl);
if (filename.size()==0)
{
+ GimmickDebugMessage(5,
+ "Pushing unknown image in queue"
+ <<std::endl);
mImageEventQueue.push_back(ImageEventType(image));
return;
}
- std::map<std::string,tree::Node*>::iterator i;
+ std::map<std::string,tree::Node*>::iterator i;
i = mImageFileNameToNode.find(filename);
if (i!=mImageFileNameToNode.end())
{
- mImageEventQueue.push_back(ImageEventType(i->second,image));
+ GimmickDebugMessage(5,
+ "Pushing image of file '"<<i->second<<"' in queue"
+ <<std::endl);
+ mImageEventQueue.push_back(ImageEventType(i->second,image));
}
}
virtual void GetSelectedFiles(std::vector<std::string>& s)
{ GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
+ virtual void OnSelectionChange(std::vector<tree::Node*>& s)
+ { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
bool ValidateSelected (std::vector<tree::Node*>& sel, int min_dim, int max_dim);
namespace creaImageIO
{
// CTor
- TreeView::TreeView(TreeHandler* handler)
- : mTreeHandler(handler)
+ TreeView::TreeView(TreeHandler* handler, GimmickView* gimmick )
+ : mTreeHandler(handler),
+ mGimmickView(gimmick)
{
GimmickDebugMessage(1,"TreeView::TreeView"
<<std::endl);
namespace creaImageIO
{
+
+ class GimmickView;
+
/**
* \ingroup View
*/
//=====================================================================
-
+
//=====================================================================
/// Abstract class that handles the view of a Tree through its TreeHandler
class TreeView
{
public:
/// Ctor
- TreeView(TreeHandler*);
+ TreeView(TreeHandler*,GimmickView*);
/// Virtual destructor
virtual ~TreeView();
protected:
TreeHandler* GetTreeHandler() { return mTreeHandler; }
+ GimmickView* GetGimmickView() { return mGimmickView; }
private:
/// The TreeHandler with which it corresponds
TreeHandler* mTreeHandler;
- };
+ /// The GimmickView which holds the TreeView
+ GimmickView* mGimmickView;
+
+ };
// EO class TreeView
//=====================================================================
///Callback method on a selection
void WxGimmickReaderDialog::OnValid(wxCommandEvent& event)
{
- bool t=mView->ValidateSelection(event.GetClientData());
- mOkButton->Enable(t);
+ // bool t=mView->ValidateSelection(event.GetClientData());
+ // TO DO
+ // mOkButton->Enable(t);
}
int number_of_threads)
: wxPanel(parent,id,pos,size),
GimmickView(gimmick, number_of_threads),
- mProgressDialog(0)
+ mProgressDialog(0),
+ mConstructed(false)
{
GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
<<std::endl);
SetSizer( sizer );
SetAutoLayout(true);
Layout();
-
+
+ mConstructed = true;
}
//======================================================================
GimmickMessage(2,"Creating the tree view for '"<<
name<<"'"<<std::endl);
// Create the WxTreeView
- WxTreeView* view = new WxTreeView(h,mNotebook,-1);
+ WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
// TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
// ALREADY IN THE MAP
//=================================================
//=================================================
- bool WxGimmickView::ValidateSelection(void * s)
+ void WxGimmickView::OnSelectionChange(std::vector<tree::Node*>& sel)
{
+ GimmickDebugMessage(5,
+ "WxGimmickView::OnSelectionChange"
+ <<std::endl);
wxBusyCursor busy;
- std::vector<tree::Node*> sel=* (std::vector<tree::Node*> *) s;
- bool valid=ValidateSelected(sel,mSelectionMinDimension,mSelectionMaxDimension );
- mText->SetLabel(_T("Status: ")+GetMessage());
- if(valid)
- {
- ReadImageThreaded(sel);
- }
- else
- {
- mViewer->Hide();
- }
- return valid;
+ bool valid = ValidateSelected(sel,
+ mSelectionMinDimension,
+ mSelectionMaxDimension );
+ mText->SetLabel(_T("Status: ")+crea::std2wx(GetMessage()));
+ if(valid)
+ {
+ ReadImageThreaded(sel);
+ }
+ else
+ {
+ mViewer->Hide();
+ }
+
}
///Reads Images (Threaded)
void WxGimmickView::ReadImageThreaded(std::vector<tree::Node*> sel)
{
- int maxprio = GetMaximalPriority();
- int prio = maxprio + 2000;
-
- //First load the selected images
- mCurImageItemToShow = sel.front();
- std::vector<tree::Node*>::iterator selected;
- for(selected=sel.begin();selected!=sel.end();++selected)
+ GimmickDebugMessage(5,
+ "ReadImageThreaded"
+ <<std::endl);
+ int maxprio = GetMaximalPriority();
+ int prio = maxprio + 2000;
+
+ //First load the selected images
+ mCurImageItemToShow = sel.front();
+ std::vector<tree::Node*>::iterator selected;
+ for(selected=sel.begin();selected!=sel.end();++selected)
{
GimmickDebugMessage(5,
"Requesting image from selected "
/// Processes the queue of image events
void WxGimmickView::ProcessImageEvents()
{
- int level=GetTreeViewMap()["Local database"]->GetNumberOfLevels();
- std::vector<tree::Node*> sel=GetTreeViewMap()["Local database"]->GetSelected(level+1);
- GimmickDebugMessage(5,
- "Processing Images. Lock Started"
- <<std::endl);
- MultiThreadImageReaderEventLock();
+ if (!mConstructed) return;
- mViewer->ClearImages();
+ int level=GetTreeViewMap()["Local database"]->GetNumberOfLevels();
+ std::vector<tree::Node*> sel=GetTreeViewMap()["Local database"]->GetSelected(level+1);
+ GimmickDebugMessage(5,
+ "Processing Images. Lock Started"
+ <<std::endl);
+ MultiThreadImageReaderEventLock();
+
+ mViewer->ClearImages();
while (!IsQueueEmpty())
{
- vtkImageData* image=GetNextImageQueued();
- tree::Node* node=GetNextNodeQueued();
- if( image!=0 )
- {
- bool found=false;
- std::vector<tree::Node*>::iterator i;
- for(i=sel.begin();i!=sel.end()&&!found;++i)
- {
- if((*i)==node)
- {
- mViewer->AddImage(image);
- found=true;
- }
- }
- UnqueueNext();
- }
- }
- if(!(mViewer->ImagesEmpty()))
+ GimmickDebugMessage(5,
+ "Queue not empty"
+ <<std::endl);
+
+ vtkImageData* image=GetNextImageQueued();
+ if( image!=0 )
{
- mViewer->ShowImages();
- mViewer->Show();
+ tree::Node* node=GetNextNodeQueued();
+
+ bool found=false;
+ std::vector<tree::Node*>::iterator i;
+ for(i=sel.begin();i!=sel.end()&&!found;++i)
+ {
+ if((*i)==node)
+ {
+ mViewer->AddImage(image);
+ found=true;
+ }
+ }
}
+ UnqueueNext();
+ }
+ if(!(mViewer->ImagesEmpty()))
+ {
+ GimmickDebugMessage(5,
+ "Showing images"
+ <<std::endl);
+ mViewer->ShowImages();
+ mViewer->Show();
+ }
ClearQueue();
int number_of_threads = 0);
/// Virtual destructor
virtual ~WxGimmickView();
-
- /// Returns the selected Images so that they comply with the given parameter(<4D)
- ///(overloaded from GimmickView)
- vtkImageData* GetSelectedImage(int dim);
- /// Returns the selected files
- ///(overloaded from GimmickView)
- void GetSelectedFiles(std::vector<std::string>& s);
+
+ /// Returns the selected Images so that they comply with the given parameter(<4D)
+ ///(overloaded from GimmickView)
+ vtkImageData* GetSelectedImage(int dim);
+ /// Returns the selected files
+ ///(overloaded from GimmickView)
+ void GetSelectedFiles(std::vector<std::string>& s);
/// Returns the selected Images so that they comply with the given parameter(4D)
//(overloaded from GimmickView)
- void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
- /// Validates the selected images
- bool ValidateSelection(void *);
- ///Sends a request to read the currently selected node and the ones that surround it.
- void ReadImageThreaded(std::vector<tree::Node*> sel);
+ void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
+ /// Callback called when a selection from a TreeView has changed
+ //(overloaded from GimmickView)
+ void OnSelectionChange(std::vector<tree::Node*>& s);
+
+
+ ///Sends a request to read the currently selected node and the ones that surround it.
+ void ReadImageThreaded(std::vector<tree::Node*> sel);
+
protected:
/// Creates the tool bar
private:
+ /// Is set to true at the end of constructor
+ /// (in order to lock callbacks from threaded objects or event
+ /// before everything is ok)
+ bool mConstructed;
/// The ToolBar and the tools
wxToolBar* mToolBar;
wxToolBarToolBase* mToolAddFile;
#include <creaImageIOWxTreeView.h>
+#include <creaImageIOGimmickView.h>
#include <creaImageIOSystem.h>
#include <wx/splitter.h>
///Comparing function for ordering algorithm. Takes parameters as strings.
//=====================================================================
// CTor
WxTreeView::WxTreeView(TreeHandler* handler,
+ GimmickView* gimmick,
wxWindow* parent,
const wxWindowID id)
: wxPanel(parent,id),
- TreeView(handler)
+ TreeView(handler,gimmick)
{
GimmickDebugMessage(1,"WxTreeView::WxTreeView"
<<std::endl);
" Level "<<level+1
<<std::endl);
if (level<mLevelList.size()-1) UpdateLevel( level + 2 );
- if (level==mLevelList.size()-1) ValidateSelectedImages ();
+ if (level==mLevelList.size()-1) ValidateSelectedImages ();
}
//================================================================
}
//================================================================
+
+ //================================================================
void WxTreeView::ValidateSelectedImages()
{
- //Send an event telling wether the selection is valid or not
- wxCommandEvent event( 0, GetId() );
- event.SetEventObject( this );
- std::vector<tree::Node*> sel=GetSelected((mLevelList.size()+1));
- event.SetClientData(&sel);
- GetEventHandler()->ProcessEvent( event );
+ GimmickDebugMessage(7,
+ "WxTreeView::ValidateSelectedImages"
+ <<std::endl);
+ std::vector<tree::Node*> sel(GetSelected(mLevelList.size()+1));
+ GetGimmickView()->OnSelectionChange(sel);
+ /*
+ //Send an event telling wether the selection is valid or not
+ wxCommandEvent event( 0, GetId() );
+ event.SetEventObject( this );
+ std::vector<tree::Node*> sel=GetSelected((mLevelList.size()+1));
+ event.SetClientData(&sel);
+ GetEventHandler()->ProcessEvent( event );
+ */
+ //
}
+ //================================================================
+
- //================================================================
+ //================================================================
void WxTreeView::GetNodes(std::vector<tree::Node*>& nodes, bool direction)
{
long item = mLastSelected;
namespace creaImageIO
{
+
/**
* \ingroup View
*/
{
public:
/// Ctor
- WxTreeView(TreeHandler*, wxWindow* parent, const wxWindowID id);
+ WxTreeView(TreeHandler*, GimmickView*,
+ wxWindow* parent, const wxWindowID id);
/// Virtual destructor
virtual ~WxTreeView();
/// Callback for column click
void OnColClick(wxListEvent& event);
- private:
+ private:
/// The struct holding the data for one level
/// Holds the wx control and other data
/// such as the vector of attribute keys corresponding to the columns
int mx1,mx2,my1,my2,mz1,mz2;
double mspx,mspy,mspz;
};
+
+ //=====================================================================
- // CTor
+
+
+
+ //=====================================================================
+ // CTor
WxViewer::WxViewer(wxWindow *parent,
wxWindowID id,
wxString title,
wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
- // previewer
+ // previewer
- mInteractor = new crea::creawxVTKRenderWindowInteractor(this,-1);
+ mInteractor = new crea::creawxVTKRenderWindowInteractor(this,-1);
mInteractor->UseCaptureMouseOn();
mViewer = vtkImageViewer2::New();
mViewer->SetupInteractor ( mInteractor );
-
- mMovie=new ThreadedMovie(images, mViewer, mInteractor, this);
+
+ mMovie=new ThreadedMovie(images, mViewer, mInteractor, this);
topsizer-> Add( mInteractor ,1,wxGROW ,0);
SetSizer( topsizer );
void WxViewer::ShowImage(vtkImageData* im)
{
- mViewer->SetInput(im);
- mViewer->SetSlice( 0 );
-
- int x1,x2,y1,y2,z1,z2;
- double spx,spy,spz;
+ GimmickDebugMessage(5,"WxViewer::ShowImage"
+ <<std::endl);
+ mViewer->SetInput(im);
+ mViewer->SetSlice( 0 );
+
+ int x1,x2,y1,y2,z1,z2;
+ double spx,spy,spz;
im->Update();
im->GetSpacing(spx,spy,spz);
im->GetExtent (x1,x2,y1,y2,z1,z2);
/*
std::cout << "-----------------------------"<<std::endl;
- std::cout << x1 << "-"<<x2<<std::endl;
- std::cout << y1 << "-"<<y2<<std::endl;
- std::cout << z1 << "-"<<z2<<std::endl;
- std::cout << spx << "-"<<spy<<"-"<<spz<<std::endl;
+ std::cout << x1 << "-"<<x2<<std::endl;
+ std::cout << y1 << "-"<<y2<<std::endl;
+ std::cout << z1 << "-"<<z2<<std::endl;
+ std::cout << spx << "-"<<spy<<"-"<<spz<<std::endl;
*/
-
+
if ((x1!=mx1) ||
(x2!=mx2) ||
(y1!=my1) ||
}
-
-
+ mInteractor->Render();
+ mViewer->Render();
}
//================================================================
void* ThreadedMovie::Entry()
{
+ GimmickMessage(1,"ThreadedMovie::Entry()"<<std::endl);
- while(true)
- {
- clock_t endwait;
- for(i=mImagesToPlay.begin();i!=mImagesToPlay.end();++i)
- {
- if(i!=mImagesToPlay.end())
- {
- ShowImage(*i);
- mParent->Refresh();
- endwait = clock () + 0.2 * CLOCKS_PER_SEC ;
- while (clock() < endwait) {}
- }
-
- }
-
- }
- return 0;
+ while(true)
+ {
+ clock_t endwait;
+ for(i=mImagesToPlay.begin();i!=mImagesToPlay.end();++i)
+ {
+ if(i!=mImagesToPlay.end())
+ {
+
+ GimmickMessage(1,"ThreadedMovie next image"<<std::endl);
+
+ ShowImage(*i);
+ mParent->Refresh();
+ endwait = clock () + 0.2 * CLOCKS_PER_SEC ;
+ while (clock() < endwait) {}
+ }
+
+ }
+
+ }
+ return 0;
}
//=====================================================================
namespace creaImageIO
{
+ class ThreadedMovie;
+
class WxViewer : public wxFrame
{
#endif // USE_WIDGETS
// EOF
-#endif
\ No newline at end of file
+#endif