- vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
- sphereMapper->SetInput( vtksphere->GetOutput() );
- vtkActor *sphereActor = vtkActor::New();
- sphereActor->SetMapper(sphereMapper);
- sphereActor->SetOrigin(0, 0, 0);
-
- std::vector<vtkActor*>::iterator itAS;
- itAS = lstActorsSphere.begin();
- lstActorsSphere.insert( itAS+pos, sphereActor);
- if(renderer==NULL){
- wxMessageDialog dialog(this, _T("Renderer Not Set"),_T("Renderer Not Set"),wxICON_ERROR);
- dialog.ShowModal();
- return;
- }
- renderer->AddActor( sphereActor );
-
- // Actor
- vtkTextActor3D *textActor = vtkTextActor3D::New();
-
- textActor->SetInput( strLabel.c_str() );
- renderer->AddActor( textActor );
- std::vector<vtkTextActor3D*>::iterator itTA;
- itTA = lstActorsText.begin();
- lstActorsText.insert( itTA+pos , textActor);
-
- RefreshPoint(pos);
- std::cout<<"WidgetShowNPoints::InsertPoint end"<<std::endl;
-}
-
-//------------------------------------------------------------------------
-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() ) );
- SetOutputBox();
- } else {//mpoint.size
- printf("creaMaracasVisu::ShowNPoints (not match point) \n");
- }
- } // renderer
-}
-
-//------------------------------------------------------------------------
-void WidgetShowNPoints::OnInsertPoint (wxCommandEvent& event)//CFT
-{
- std::cout<<"WidgetShowNPoints::OnInsertPoint begin"<<std::endl;
- 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){
- InsertPoint(mpoint[0],mpoint[1],mpoint[2], (const char*) ( textCtrl->GetValue().mb_str() ) );
- SetOutputBox();
- } else {//mpoint.size
- printf("creaMaracasVisu::ShowNPoints (not match point) \n");
- }
- } // renderer
- std::cout<<"WidgetShowNPoints::OnInsertPoint end"<<std::endl;
-}
-
-
-//------------------------------------------------------------------------
- void WidgetShowNPoints::SetOutputBox()
- {
- renderer->GetRenderWindow()->Render();
- wxString strTmp;
- strTmp.Printf(_T("Nbr of points: %d"), (int)(lstPointsX.size()) );
- txtNrPoints->SetLabel( strTmp );
-
- //--BBTK
- mbbShowNPoints->bbSetOutputlstPointsX( lstPointsX );
- mbbShowNPoints->bbSetOutputlstPointsY( lstPointsY );
- mbbShowNPoints->bbSetOutputlstPointsZ( lstPointsZ );
- mbbShowNPoints->bbSetOutputlstLabels( lstLabels );
-
- mbbShowNPoints->bbSignalOutputModification();
-
-//EED 07/07/2014
-// mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));
-// mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));
-// mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));
-// mbbShowNPoints->bbSignalOutputModification(std::string("lstLabels"));
- }
-
-//------------------------------------------------------------------------
- void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
- {
- wxFileDialog* FD = new wxFileDialog( 0,
- _T("Save points .."),
- _T(""),
- _T(""),
- _T("(*.xls)|*.xls"),
- wxSAVE | wxOVERWRITE_PROMPT,
- wxDefaultPosition);
- //EED
-
- int result_FD = FD->ShowModal();
- std::string tmpLabel;
-
- // This line is need it by windows //EED
- FD->SetReturnCode( result_FD );
-
- if (FD->GetReturnCode()==wxID_OK)
- {
- FILE *ff;
- std::string filename= (const char*) ( FD->GetPath().mb_str() );
- ff = fopen( filename.c_str() , "w+" );
- if (ff!=NULL)
- {
- int i , size = (int) (lstActorsSphere.size());
- fprintf(ff,"NumberOfPoints %d \n",size);
- fprintf(ff," X\tY\tZ\tvalue\tLabel\n");
- int x, y, z;
- double value;
- for (i=0; i<size; i++)
- {
- x=lstPointsX[i];
- y=lstPointsY[i];
- z=lstPointsZ[i];
- value= mimage->GetScalarComponentAsDouble(x,y,z,0);
- if (lstLabels[i]!="")
- {
- tmpLabel=lstLabels[i];
- } else{
- tmpLabel="<_VOID_>";
- }
- fprintf(ff,"%d\t%d\t%d\t%f\t%s\n", x , y , z , value , tmpLabel.c_str());
- } // for
- fclose(ff);
- } else { // else ff
- printf("WidgetShowNPoints::OnSavePoints ...Error... creating file");
- } //ff
- } // dialog box
- }
-
-//------------------------------------------------------------------------
- void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
- {
- wxFileDialog* FD = new wxFileDialog( 0,
- _T("Load points .."),
- _T(""),
- _T(""),
- _T("(*.xls)|*.xls"),
- wxOPEN | wxFILE_MUST_EXIST,
- wxDefaultPosition);
- //EED
-
- int result_FD = FD->ShowModal();
-
- // This line is need it by windows //EED
- FD->SetReturnCode( result_FD );
-
- if (FD->GetReturnCode()==wxID_OK)
- {
- FILE *ff;
- std::string filename= (const char*) ( FD->GetPath().mb_str() );
- ff = fopen( filename.c_str() , "r+" );
- if (ff!=NULL)
- {
- int i,size;
- char chartmp[256];
- fscanf(ff," %s %d",chartmp,&size);
- fscanf(ff," %s %s %s %s %s",chartmp, chartmp,chartmp,chartmp,chartmp );
-
- float value;
- int x,y,z;
- for (i=0; i<size; i++)
- {
- fscanf(ff,"%d%d%d%f%s",&x,&y,&z,&value,chartmp ); // x,y,z,value,label
- if (strcmp(chartmp,"<_VOID_>")==0) { strcpy(chartmp,""); }
- AddPoint(x,y,z, chartmp );
- }
- SetOutputBox();
- fclose(ff);
- } else { // else ff
- printf("WidgetShowNPoints::OnLoadPoints ...Error... reading file");
- } //ff
- } // dialog box
-
-
- }
-
-//------------------------------------------------------------------------
-
- 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==-1) && (mbbShowNPoints->bbGetInputType()==1))
- {
- id=0;
- AddPoint(0,0,0,"");
- SetOutputBox();
- }
-
-
- 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());
- double spc[3];
-
- if(mimage ==NULL){
- wxMessageDialog* diag = new wxMessageDialog(this, _T("Image not set"), _T("Image Not Set"), wxICON_ERROR);
- diag->ShowModal();
- return -1;
- }else{
-
- mimage->GetSpacing(spc);
-
- for ( i=0 ; i<size; i++ )
- {
- double rx = spc[0]*(mpoint[0] - lstPointsX [i]);
- double ry = spc[1]*(mpoint[1] - lstPointsY [i]);
- double rz = spc[2]*(mpoint[2] - lstPointsZ [i]);
- if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
- {
- id=i;
- } // if
- } // for
-
- return id;
- }
- }
-
-//------------------------------------------------------------------------
- void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
- {
- int id=IdInsidePoint();
- if (id>=0)
- {
- std::string strLabel = CleanSpaces( (const char*) ( textCtrl->GetValue().mb_str() ) );
- lstLabels[id] = CleanSpaces( (const char*) (textCtrl->GetValue().mb_str()) ) ;
- lstActorsText[id]->SetInput( lstLabels[id].c_str() );
- SetOutputBox();
- }
- }
-
-//------------------------------------------------------------------------
- void WidgetShowNPoints::ErasePoint(int id)
- {
- if (this->renderer!=NULL){
- if (id>=0){
- renderer->RemoveActor( lstActorsSphere[id] );
- renderer->RemoveActor( lstActorsText[id] );
- lstActorsSphere[id]->Delete();
- lstActorsText[id]->Delete();
- lstSourceSphere[id]->Delete();
- lstActorsSphere.erase( lstActorsSphere.begin()+id );
- lstActorsText.erase( lstActorsText.begin()+id );
- lstSourceSphere.erase( lstSourceSphere.begin()+id );
-
- lstPointsX.erase( lstPointsX.begin()+id );
- lstPointsY.erase( lstPointsY.begin()+id );
- lstPointsZ.erase( lstPointsZ.begin()+id );
- lstLabels.erase( lstLabels.begin()+id );
-
- SetOutputBox();
-
- } // if id
- } // if renderer
- }
-
-//------------------------------------------------------------------------
- void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
- {
- ErasePoint( IdInsidePoint() );
- }
-
-//------------------------------------------------------------------------
- void WidgetShowNPoints::OnEraseLastPoint(wxCommandEvent& event)
- {
- ErasePoint(lstActorsSphere.size()-1);
- }
-
-//------------------------------------------------------------------------
-void WidgetShowNPoints::OnDeleteAllPoints(wxCommandEvent& event)
-{
- int id,size=lstActorsSphere.size();
- for (id=size-1;id>=0;id--)
- {
- ErasePoint(id);
- }
-}
-
-//NTU: Method for updating points opacity and Radio
-
-//------------------------------------------------------------------------
-void WidgetShowNPoints::UpdatePoints(wxCommandEvent &event)
-{
- //Difference in Radio for text placement
- int difradio = sdrRadio->GetValue() - this->mradio;
-
- this->mopacity = sdrOpacity->GetValue()/100.0;
- this->mradio = sdrRadio->GetValue();
-
- //NTU refresh the inputs
- mbbShowNPoints->bbSetInputOpacity(this->mopacity);
- mbbShowNPoints->bbSetInputRadio(this->mradio);
-
- int size = (int) this->lstActorsSphere.size();
- int i;
- for(i = 0; i < size; i ++)
- {
- this->lstSourceSphere[i]->SetRadius(mradio);
- this->lstActorsSphere[i]->GetProperty()->SetOpacity(mopacity);
- this->lstActorsText[i]->GetTextProperty()->SetOpacity(mopacity);
- this->lstActorsText[i]->SetPosition(this->lstActorsText[i]->GetPosition()[0]+difradio,this->lstActorsText[i]->GetPosition()[1], this->lstActorsText[i]->GetPosition()[2]);
- }
-
- //NTU: For updating
-//EED SetOutputBox();
- renderer->GetRenderWindow()->Render();
-
-}