# Viewer
creaImageIOWxViewer
+creaImageIOImagePointerHolder.h
)
namespace creaImageIO
{
+
//======================================================================
// CTor
GimmickView::GimmickView(Gimmick* gimmick, int threads)
//======================================================================
///Requests the reading of an image
void GimmickView::RequestReading(tree::Node* n,
- int prio, int selection_index)
+ int prio, int selection_index, ImagePointerHolder *p)
{
- mReader.Start();
- ImageEventType t(n,0,selection_index);
+ mReader.Start();
+ ImageEventType t(n,selection_index, p);
mImageEventMap[n->GetAttribute("FullFileName")] = t;
mReader.Request(this,n->GetAttribute("FullFileName"),prio);
}
{
if (filename.size()==0)
{
- GimmickDebugMessage(5,
- "Pushing unknown image in queue"
- <<std::endl);
- mImageEventQueue.push_back(ImageEventType(image));
- return;
+ GimmickDebugMessage(5,
+ "Pushing unknown image in queue"
+ <<std::endl);
+ mImageEventQueue.push_back(ImageEventType(image));
+ return;
}
ImageEventTypeMap::iterator i;
i = mImageEventMap.find(filename);
if (i!=mImageEventMap.end())
{
- GimmickDebugMessage(5,
- "Pushing image of file '"<<filename<<"' in queue"
- <<std::endl);
- ImageEventType e(i->second);
- e.image = image;
- mImageEventQueue.push_back(e);
- mImageEventMap.erase(i);
+ GimmickDebugMessage(5,
+ "Putting image of file '"<<filename<<"' on pointer"
+ <<std::endl);
+ ImageEventType ie(i->second);
+ ie.image = image;
+ ie.pointerHolder->Set(ie.image);
+ //mImageEventMap.erase(i);
}
}
else if (e==Error)
mess+=filename;
mess+="\n";
GimmickMessage(1,mess);
+ ImageEventTypeMap::iterator i;
+ i = mImageEventMap.find(filename);
+ if (i!=mImageEventMap.end())
+ {
+ ImageEventType ie(i->second);
+ ie.image = image;
+ ie.pointerHolder->Set(GetDefaultImage());
+ //mImageEventMap.erase(i);
+ }
}
else if (e==ImageUnloaded)
mess+=filename;
mess+="\n";
GimmickMessage(1,mess);
+ ImageEventTypeMap::iterator i;
+ i = mImageEventMap.find(filename);
+ if (i!=mImageEventMap.end())
+ {
+ ImageEventType ie(i->second);
+ ie.image = image;
+ ie.pointerHolder->Set(GetDefaultImage());
+ //mImageEventMap.erase(i);
+ }
+
}
}
#include <creaImageIOGimmick.h>
#include <creaImageIOTreeView.h>
#include <creaImageIOSystem.h>
+#include <creaImageIOImagePointerHolder.h>
//#include <map>
#include <vtkImageData.h>
/**
* \ingroup View
*/
+
+
//=====================================================================
//=====================================================================
class GimmickView: public MultiThreadImageReaderUser
{
public:
+
/// Ctor
GimmickView(Gimmick*, int number_of_threads = 0 );
/// Virtual destructor
void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<tree::Node*> im, int dim);
///Requests the reading of an image with priority and index in the
/// current selection (-1 if not in selection)
- void RequestReading(tree::Node* n, int prio, int selection_index);
+ void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
///Returns true if the ImageEventQueue is empty
bool IsQueueEmpty(){return mImageEventQueue.empty();}
/// else it has been unloaded
struct ImageEventType
{
- ImageEventType( tree::Node* no = 0,
- vtkImageData* im = 0,
- int sel_index = -1)
- : node(no), image(im), index(sel_index) {}
+ ImageEventType( tree::Node* no = 0,
+ int sel_index = -1,
+ ImagePointerHolder* ph= 0)
+ : node(no), index(sel_index), pointerHolder(ph){}
ImageEventType(vtkImageData* im )
: image(im) {}
tree::Node* node;
vtkImageData* image;
- int index;
+ int index;
+ ImagePointerHolder* pointerHolder;
};
typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
/// Map of images' names to ImageEventType
} // EO namespace creaImageIO
// EOF
-#endif
+#endif
namespace creaImageIO
{
+
//======================================================================
// The ids of the different tools
enum
// Previewer
mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
- mViewer->SetMovieSize(1);
- mViewer->SetImage(0,GetDefaultImage());
- mViewer->ShowNextImage();
+ pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
+ mViewer->SetImageVector(pointers);
+ mViewer->StartPlayer();
+
bottom_sizer->Add(mViewer,1,wxGROW,1);
// mViewer->Show();
}
else
{
- mViewer->SetMovieSize(1);
- mViewer->SetImage(0,GetDefaultImage());
- // mViewer->Hide();
+ ClearSelection();
}
int maxprio = GetMaximalPriority();
int prio = maxprio + 2000;
- mViewer->SetMovieSize(sel.size());//ClearImages();
-
+ if(sel.size()>0)
+ {
//First load the selected images
mCurImageItemToShow = sel.front();
+ pointers.clear();
int index = 0;
std::vector<tree::Node*>::iterator selected;
-
for(selected=sel.begin();selected!=sel.end();++selected)
{
GimmickDebugMessage(5,
"Requesting image from selected "
<<(*selected)->GetAttribute("FullFileName")
<<std::endl);
- RequestReading(*selected,prio,index);
+ ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
+ pointers.push_back(ph);
+ RequestReading(*selected,prio,index,ph);
// AddEntryToMap(*selected);
prio--;
index++;
}
-
+ mViewer->SetImageVector(pointers);
//Going up
prio = maxprio + 20;
std::vector<tree::Node*> up;
"Requesting image from neighbors up "
<<(*iterUp)->GetAttribute("FullFileName")
<<std::endl);
- RequestReading(*iterUp,prio,-1);
+ ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
+ RequestReading(*iterUp,prio,-1,ph);
// AddEntryToMap(*iterUp);
prio--;
if (prio == maxprio) break;
"Requesting image from neighbors down "
<<(*iterDown)->GetAttribute("FullFileName")
<<std::endl);
- RequestReading(*iterDown,prio,-1);
+ ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
+ RequestReading(*iterDown,prio,-1,ph);
// AddEntryToMap(*iterDown);
prio--;
if (prio == maxprio) break;
- }
+ }
+ }
}
//==================================================
- //==================================================
- /// Processes the queue of image events
- void WxGimmickView::ProcessImageEvents()
- {
- if (!mConstructed) return;
-
- // 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();
-
-
- while (!IsQueueEmpty())
- {
- mViewer->StartPlayer();
-
- GimmickDebugMessage(5,
- "Queue not empty"
- <<std::endl);
-
- vtkImageData* image = GetNextImageQueued();
- if( image!=0 )
- {
- int index = GetNextSelectionIndexQueued();
- if (index>=0)
- {
- mViewer->SetImage(index,image);
- }
-
- }
- UnqueueNext();
- }
-
- ClearQueue();
-
- MultiThreadImageReaderEventUnlock();
- /*
- GimmickDebugMessage(5,
- "Processing Images. Lock Ended"
- <<std::endl);
- */
- }
-
//==================================================
//==================================================
void WxGimmickView::OnInternalIdle()
{
if (!mConstructed) return;
- ProcessImageEvents();
static bool first_time = true;
if (false)
- {
- mViewer->SetMovieSize(1);
- mViewer->SetImage(0,GetDefaultImage());
- first_time = false;
+ {
+ first_time = false;
}
// GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
// mViewer->StartPlayer();
- if (mViewer->RefreshIfNecessary())
- {
- // mViewer->Refresh();
- // mViewer->SetFocus();
- }
+ mViewer->RefreshIfNecessary();
}
//==================================================
//==================================================
void WxGimmickView::ClearSelection()
{
- mViewer->SetMovieSize(1);
- mViewer->SetImage(0,GetDefaultImage());
+ pointers.clear();
+ pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
+ mViewer->SetImageVector(pointers);
mViewer->RefreshIfNecessary();
}
//=====================================================================
/// Concrete derivative of GimmickView which implements a wxWidgets-based view
+
class WxGimmickView : public wxPanel, virtual public GimmickView
{
public:
+
typedef int EventType;
/// Ctor
/// AddProgress Gimmick callback
void OnAddProgress( Gimmick::AddProgress& );
- /// Processes the queue of image events
- /// Called in OnInternalIdle();
- /// (locks the MultiThreadImageReaderEvent mutex)
- void ProcessImageEvents();
/// Called upon to refresh the viewer once there are no actions to be done
void OnInternalIdle();
WxViewer* mViewer;
///Currently Displayed Node
tree::Node* mCurImageItemToShow;
+ //Pointer holders for images to be shown
+ std::vector<ImagePointerHolder*> pointers;
wxString mCurrentDirectory;
mLastSelected=0;
mDirection=true;
mSelectionMade=false;
+ mProcess=true;
CreateColorPalette();
UpdateLevel(1);
{
mSelected=GetSelected(level+2);
}
- else
+ else if(mProcess)
{
mLastLevelSelected=GetSelected(level+2);
}
+ else
+ {
+ event.Veto();
+ }
if (level<mLevelList.size()-1)
{
GetGimmickView()->ClearSelection();
}
if (level==mLevelList.size()-2) SelectLowerLevel();
- if (level==mLevelList.size()-1) ValidateSelectedImages ();
+ if (level==(mLevelList.size()-1)&&mProcess)
+ {
+ ValidateSelectedImages ();
+ }
}
else
{
}
+
}
//================================================================
{
long item = -1;
int level=mLevelList.size()-1;
+
for ( ;; )
{
item = GetCtrl(level)->GetNextItem(item,
wxLIST_NEXT_ALL);
if ( item == -1 )
break;
+
+ if(item==(GetCtrl(level)->GetItemCount()-1))
+ {
+ mProcess=true;
+ }
+ else
+ {
+ 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);
}
+
}
std::vector<std::string> mColorPalette;
///Boolean declaring if the last level selection has been made
bool mSelectionMade;
-
+ bool mProcess;
DECLARE_EVENT_TABLE()
};
namespace creaImageIO
{
-
+
//=====================================================================
//=====================================================================
}
//================================================================
-
+ void WxViewer::SetImageVector(std::vector<ImagePointerHolder*>& pointers)
+ {
+ wxMutexLocker lock(mMutex);
+ GimmickMessage(1,"WxViewer::SetImageVector"<<std::endl);
+ imagePointers=pointers;
+ }
//================================================================
<<mCurrent+1<<"/"
<<images.size()<<std::endl);
-
- if (mCurrent<images.size())
- {
- ShowImage(images[mCurrent]);
- if ( images[mCurrent] != mLastImageShown ) mNeedRefresh = true;
- mLastImageShown = images[mCurrent];
- }
- mCurrent++;
- if (mCurrent >= images.size()) mCurrent = 0;
+ if(imagePointers.size()>0)
+ {
+ if (mCurrent<imagePointers.size())
+ {
+ ImagePointerHolder* iph=imagePointers[mCurrent];
+ vtkImageData* currIm=iph->Get();
+ ShowImage(currIm);
+ if ( currIm != mLastImageShown )
+ {
+ mNeedRefresh = true;
+ mLastImageShown = currIm;
+ }
+ mCurrent++;
+ }
+ else
+ {
+ mCurrent = 0;
+ ImagePointerHolder* iph=imagePointers[mCurrent];
+ vtkImageData* currIm=iph->Get();
+ ShowImage(currIm);
+ if ( currIm != mLastImageShown )
+ {
+ mNeedRefresh = true;
+ mLastImageShown = currIm;
+ }
+ mCurrent++;
+ }
+ }
}
//================================================================
#include <wx/splitter.h>
#include <creaImageIOSystem.h>
+#include <creaImageIOImagePointerHolder.h>
// For image preview
// vtk and wxvtk classes
class WxViewer : public wxPanel
{
-
+
public:
// friend class ThreadedMovie;
/// Ctor
bool RefreshIfNecessary();
+ void SetImageVector(std::vector<ImagePointerHolder*>& pointers);
+
+
private:
///Shows the image passed as parameter
void ShowImage(vtkImageData* im);
///
bool mNeedRefresh;
+
+
vtkImageData* mLastImageShown;
+ std::vector<ImagePointerHolder*> imagePointers;
};