WidgetShowNPoints::WidgetShowNPoints(wxWindow *parent, bbcreaMaracasVisu::ShowNPoints *box)
: wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
{
- mbbShowNPoints = box;
- this->renderer = NULL;
- wxPanel *panel = this;
- wxSizer *sizer = NULL;
+ mbbShowNPoints = box;
+ this->renderer = NULL;
+ wxPanel *panel = this;
+ wxSizer *sizer = NULL;
// Widget interface
- askPointLabel = new wxStaticText(panel, -1, _T("Point label :")); // JPR
- textCtrl = new wxTextCtrl(panel, -1);
- wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
- wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Rename point"));
- wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point"));
- wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point"));
- wxButton *btnDeleteAllPoints= new wxButton( panel, -1, _T("Delete all points"));
- wxButton *btnSavePoints = new wxButton( panel, -1, _T("Save points"));
- wxButton *btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
- txtNrPoints = new wxStaticText(panel,-1, _T(" "));
+ askPointLabel = new wxStaticText(panel, -1, _T("Point label :")); // JPR
+ textCtrl = new wxTextCtrl(panel, -1);
+ wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
+ wxButton *btnSetPositionPoint = new wxButton( panel, -1, _T("Set nearest point"));
+ wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Rename point"));
+ wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point"));
+ wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point"));
+ wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points"));
+ wxButton *btnSavePoints = new wxButton( panel, -1, _T("Save points"));
+ wxButton *btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
+ txtNrPoints = new wxStaticText(panel,-1, _T(" "));
//NTU: Sliders for opacity and radio change
wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
// sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
- Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
- Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
- Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
- Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
- Connect(btnDeleteAllPoints->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
- Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
- Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
+ Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
+ Connect(btnSetPositionPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSetPoint);
+ Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
+ Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
+ Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
+ Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
+ Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
+ Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
//NTU: Slider events
Connect(sdrOpacity->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &WidgetShowNPoints::UpdatePoints);
sizer1->Add(askPointLabel); // JPR
sizer1->Add(textCtrl);
sizer1->Add(btnAddPoint);
+ sizer1->Add(btnSetPositionPoint);
sizer1->Add(btnRenamePoint);
sizer1->Add(btnErasePoint);
sizer1->Add(btnEraseLastPoint);
return ss;
}
+
+//------------------------------------------------------------------------
+
+void WidgetShowNPoints::RefreshPoint(int id)
+{
+ int x = lstPointsX[id];
+ int y = lstPointsY[id];
+ int z = lstPointsZ[id];
+
+ double spc[3];
+ mimage->GetSpacing(spc);
+
+ lstActorsSphere[id]->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
+ lstActorsSphere[id]->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
+ lstActorsSphere[id]->GetProperty()->SetOpacity( mopacity );
+
+ lstActorsText[id]->SetPosition( mradio+spc[0]*x , spc[1]*y , spc[2]*z );
+}
+
+
//------------------------------------------------------------------------
void WidgetShowNPoints::AddPoint(int x, int y, int z, std::string label)
{
vtkActor *sphereActor = vtkActor::New();
sphereActor->SetMapper(sphereMapper);
sphereActor->SetOrigin(0, 0, 0);
+
+
+/*EED Borrame
double spc[3];
if(mimage==NULL){
wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
sphereActor->SetPosition( spc[0]*x , spc[1]*y , spc[2]*z );
sphereActor->GetProperty()->SetColor( mcolour[0] , mcolour[1] , mcolour[2] );
sphereActor->GetProperty()->SetOpacity( mopacity );
-
+*/
+
lstActorsSphere.push_back(sphereActor);
if(renderer==NULL){
wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
// Actor
vtkTextActor3D *textActor = vtkTextActor3D::New();
+/* EED Borrame
textActor->SetPosition( mradio+spc[0]*x , spc[1]*y , spc[2]*z );
+*/
textActor->SetInput( strLabel.c_str() );
renderer->AddActor( textActor );
lstActorsText.push_back(textActor);
+ RefreshPoint(lstPointsX.size()-1);
+
+
SetOutputBox();
}
//------------------------------------------------------------------------
void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
{
+ if(mimage==NULL){
+ wxMessageDialog dialog(this, _T("Image Not Set"),_T("Image Not Set"),wxICON_ERROR);
+ dialog.ShowModal();
+ return;
+ }
+
if (this->renderer!=NULL){
if (mpoint.size()==3){
AddPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
//------------------------------------------------------------------------
int WidgetShowNPoints::GetNearestPoint()
+ {
+ int id=-1;
+ int i, size=(int)(lstActorsSphere.size());
+ double radioMin=10000000;
+
+ if(mimage ==NULL){
+ wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
+ diag->ShowModal();
+ return -1;
+ }else{
+
+ for ( i=0 ; i<size; i++ )
+ {
+ double rx = mpoint[0] - lstPointsX [i];
+ double ry = mpoint[1] - lstPointsY [i];
+ double rz = mpoint[2] - lstPointsZ [i];
+ double radio = rx*rx + ry*ry + rz*rz;
+ if ( radio <= radioMin)
+ {
+ radioMin=radio;
+ id=i;
+ } // if
+ } // for
+
+ return id;
+ }
+ }
+
+
+ //------------------------------------------------------------------------
+ void WidgetShowNPoints::OnSetPoint(wxCommandEvent& event)
+ {
+ int id=GetNearestPoint();
+ if (id>=0)
+ {
+ printf("WidgetShowNPoints::OnSetPoint \n");
+ lstPointsX[id] = mpoint[0];
+ lstPointsY[id] = mpoint[1];
+ lstPointsZ[id] = mpoint[2];
+ RefreshPoint(id);
+ /*EED Borrame
+ this->lstActorsSphere[id]->SetPosition( spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
+ this->lstActorsText[id]->SetPosition( spc[0]*mpoint[0]+difradio, spc[1]*mpoint[1], spc[2]* mpoint[2] );
+ */
+ } // if id
+ SetOutputBox();
+ }
+
+
+ //------------------------------------------------------------------------
+
+ int WidgetShowNPoints::IdInsidePoint()
{
int id=-1;
int i, size=(int)(lstActorsSphere.size());
}
}
+
//------------------------------------------------------------------------
void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
{
- int id=GetNearestPoint();
+ int id=IdInsidePoint();
if (id>=0)
{
std::string strLabel = CleanSpaces( (const char*) ( textCtrl->GetValue().mb_str() ) );
//------------------------------------------------------------------------
void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
{
- ErasePoint( GetNearestPoint() );
+ ErasePoint( IdInsidePoint() );
}
//------------------------------------------------------------------------