_brushsize = 1;
_brushform = 0; // 0 rectangle-box , 1 circle-sphere
_2D3D = 0; // 0 2D , 1 true 3D
- _brushtool = 0; // 0 pensil , 1 fill
+ _brushtool = 0; // 0 pencil , 1 fill
+
+ _minX=0;
+ _minY=0;
+ _minZ=0;
+ _maxX=0;
+ _maxY=0;
+ _maxZ=0;
}
//---------------------------------------------------------------------------
void ManualPaintModel::SetImage(vtkImageData *image)
{
_image=image;
+
+ int ext[6];
+ _image->GetWholeExtent(ext);
+ _minX=0;
+ _minY=0;
+ _minZ=0;
+ _maxX=ext[1]-ext[0];
+ _maxY=ext[3]-ext[2];
+ _maxZ=ext[5]-ext[4];
}
void ManualPaintModel::PaintImage(int px,int py, int pz)
+{
+ if (_brushtool==0)
+ {
+ BrushTool(px,py,pz);
+ }
+ if (_brushtool==1)
+ {
+ FillTool(px,py,pz);
+ }
+}
+
+
+void ManualPaintModel::FillTool(int px,int py, int pz)
+{
+ if ((px>=_minX) && (px<=_maxX) && (py>=_minY) && (py<=_maxY) && (pz>=_minZ) && (pz<=_maxZ))
+ {
+ _graylevelbasefill = _image->GetScalarComponentAsDouble(px,py,pz, 0);
+ _pxfill = px;
+ _pyfill = py;
+ _pzfill = pz;
+ _distbasefill = _distancefill*_distancefill;
+ FillToolRecursive(px,py,pz);
+ } //if _minX _maxX _minY _maxY _minZ _maxZ
+}
+
+
+void ManualPaintModel::FillToolRecursive(int px,int py, int pz)
+{
+
+ double dist=(px-_pxfill) * (px-_pxfill) + (py-_pyfill) * (py-_pyfill) + (pz-_pzfill) * (pz-_pzfill);
+
+ if ((px>=_minX) && (px<=_maxX) && (py>=_minY) && (py<=_maxY) && (pz>=_minZ) && (pz<=_maxZ))
+ {
+ float value=(float)_graylevel;
+ double igl=_image->GetScalarComponentAsDouble(px,py,pz, 0);
+ if ( (igl!=_graylevel) &&
+ (igl>=_graylevelbasefill-_tolerancefill) &&
+ (igl<=_graylevelbasefill+_tolerancefill) &&
+ (dist<=_distbasefill)
+ )
+ {
+// _image->SetScalarComponentFromFloat (px,py,pz, 0, dist+500 );
+ _image->SetScalarComponentFromFloat (px,py,pz, 0, value );
+ FillToolRecursive(px+1,py,pz);
+ FillToolRecursive(px,py+1,pz);
+ FillToolRecursive(px-1,py,pz);
+ FillToolRecursive(px,py-1,pz);
+// FillToolRecursive(px,py,pz-1);
+// FillToolRecursive(px,py,pz+1);
+ }
+ } //if _minX _maxX _minY _maxY _minZ _maxZ
+}
+
+void ManualPaintModel::BrushTool(int px,int py, int pz)
{
printf("EED ManualPaintModel::PaintImage %d %d %d\n", px,py,pz);
yy=yy*yy;
for (k=minZ; k<=maxZ; k++)
{
- zz=pz-k;
- zz=zz*zz;
- if (_brushform==0)
+ if ((i>=_minX) && (i<=_maxX) && (j>=_minY) && (j<=_maxY) && (k>=_minZ) && (k<=_maxZ))
{
- _image->SetScalarComponentFromFloat (i,j,k, 0, value );
- } else if (_brushform==1)
- {
- if ((xx+yy+zz)<=rr)
+ zz=pz-k;
+ zz=zz*zz;
+ if (_brushform==0)
{
_image->SetScalarComponentFromFloat (i,j,k, 0, value );
- }
- } // _brushform
+ } else if (_brushform==1)
+ {
+ if ((xx+yy+zz)<=rr)
+ {
+ _image->SetScalarComponentFromFloat (i,j,k, 0, value );
+ }
+ } // _brushform
+
+ } //if _minX _maxX _minY _maxY _minZ _maxZ
}//k
}//j
_2D3D = dim2D3D;
}
+//---------------------------------------------------------------------------
+void ManualPaintModel::SetToleranceFill(double tolerancefill)
+{
+ _tolerancefill = tolerancefill;
+}
+
+//---------------------------------------------------------------------------
+void ManualPaintModel::SetDistanceFill(int distancefill)
+{
+ _distancefill = distancefill;
+}
+
: wxPanel(parent, -1)
{
- wxPanel *panel = this;
- wxSizer *sizer = NULL;
+ wxPanel *panel = this;
+ wxSizer *sizer = NULL;
// Widget interface
- wxStaticText *tittleText = new wxStaticText(panel, -1, _T(" Manual Paint"));
- wxStaticText *txtBrushSize = new wxStaticText(panel, -1, wxString(_T(" Brush size ")));
- _sldBrushSize = new wxSlider(panel, -1, 1, 1, 20, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
- wxStaticText *txtGrayLevel = new wxStaticText(panel, -1, wxString(_T(" Gray Level ")));
- _sldGrayLevel = new wxSlider(panel, -1, 0, 0, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
- _graylevelCtrl = new wxTextCtrl(panel , -1);
+ wxStaticText *tittleText = new wxStaticText(panel, -1, _T(" Manual Paint"));
+ wxStaticText *txtBrushSize = new wxStaticText(panel, -1, wxString(_T(" Brush size ")));
+ _sldBrushSize = new wxSlider(panel, -1, 1, 1, 20, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
+ wxStaticText *txtGrayLevel = new wxStaticText(panel, -1, wxString(_T(" Gray Level ")));
+ _sldGrayLevel = new wxSlider(panel, -1, 0, 0, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
+ _graylevelCtrl = new wxTextCtrl(panel , -1);
+ _txtToleranceFill = new wxStaticText(panel, -1, wxString(_T(" Tolerance fill ")));
+ _sldToleranceFill = new wxSlider(panel, -1, 50, 0, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
+ _tolerancefillCtrl = new wxTextCtrl(panel , -1,_T("50") );
+ _txtDistanceFill = new wxStaticText(panel, -1, wxString(_T(" Distance fill ")));
+ _sldDistanceFill = new wxSlider(panel, -1, 50, 1, 50, wxDefaultPosition, wxDefaultSize, wxSL_LABELS);
+ _distancefillCtrl = new wxTextCtrl(panel , -1,_T("50") );
+
wxString lst2D3D[2];
lst2D3D[0]=_T("2D circle");
lst2D3D[1]=_T("3D sphere");
_rb2D3D = new wxRadioBox(panel, -1, _T("2D / 3D"), wxDefaultPosition, wxSize(270,45), 2 , lst2D3D, 2, wxRA_SPECIFY_COLS);
_rb2D3D->SetSelection(1);
- _rb2D3D->Disable();
wxString lstBrushForm[2];
lstBrushForm[0]=_T("rectangle/cube");
lstBrushForm[1]=_T("circle/sphere");
_rbBrushForm = new wxRadioBox(panel, -1, _T("Brush form"), wxDefaultPosition, wxSize(270,45), 2 , lstBrushForm, 2, wxRA_SPECIFY_COLS);
+ _txtToleranceFill->Disable();
+ _sldToleranceFill->Disable();
+ _tolerancefillCtrl->Disable();
+
+ _txtDistanceFill->Disable();
+ _sldDistanceFill->Disable();
+ _distancefillCtrl->Disable();
+
wxString lstBrushTool[2];
- lstBrushTool[0]=_T("Pensil");
+ lstBrushTool[0]=_T("Brush");
lstBrushTool[1]=_T("Fill");
_rbBrushTool = new wxRadioBox(panel, -1, _T("Brush tool"), wxDefaultPosition, wxSize(270,45), 2 , lstBrushTool, 2, wxRA_SPECIFY_COLS);
- _rbBrushTool->Disable();
wxButton *btnCopy = new wxButton( panel, -1, _T("Copy"));
btnCopy->Disable();
wxButton *btnUndo = new wxButton( panel, -1, _T("Undo"));
btnUndo->Disable();
- Connect(_sldBrushSize->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxManualPaintPanel::OnBrushSize);
- Connect(_sldGrayLevel->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxManualPaintPanel::OnSldGrayLevel);
- Connect(_graylevelCtrl->GetId() , wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &wxManualPaintPanel::OnCtrTxtGrayLevel);
+ Connect(_sldBrushSize->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxManualPaintPanel::OnBrushSize);
+
+ Connect(_sldGrayLevel->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxManualPaintPanel::OnSldGrayLevel);
+ Connect(_graylevelCtrl->GetId() , wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &wxManualPaintPanel::OnCtrTxtGrayLevel);
- Connect(_rb2D3D->GetId() , wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &wxManualPaintPanel::On2D3D);
- Connect(_rbBrushForm->GetId() , wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &wxManualPaintPanel::OnBrushForm);
- Connect(_rbBrushTool->GetId() , wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &wxManualPaintPanel::OnBrushTool);
- Connect(btnCopy->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxManualPaintPanel::OnCopy);
- Connect(btnUndo->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxManualPaintPanel::OnUndo);
+ Connect(_sldToleranceFill->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxManualPaintPanel::OnSldToleranceFill);
+ Connect(_tolerancefillCtrl->GetId() , wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &wxManualPaintPanel::OnCtrTxtToleranceFill);
+
+ Connect(_sldDistanceFill->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxManualPaintPanel::OnSldDistanceFill);
+ Connect(_distancefillCtrl->GetId() , wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &wxManualPaintPanel::OnCtrTxtDistanceFill);
+
+ Connect(_rb2D3D->GetId() , wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &wxManualPaintPanel::On2D3D);
+ Connect(_rbBrushForm->GetId() , wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &wxManualPaintPanel::OnBrushForm);
+ Connect(_rbBrushTool->GetId() , wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &wxManualPaintPanel::OnBrushTool);
+ Connect(btnCopy->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxManualPaintPanel::OnCopy);
+ Connect(btnUndo->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxManualPaintPanel::OnUndo);
wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
+
sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
sizer1->Add(tittleText);
- sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
- sizer1->Add(txtBrushSize);
- sizer1->Add(_sldBrushSize, 1, wxGROW );
+
sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
sizer1->Add(txtGrayLevel);
sizer1->Add(_sldGrayLevel, 1, wxGROW );
sizer1->Add(_graylevelCtrl);
+
sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
sizer1->Add(_rb2D3D, 1, wxGROW );
+
+ sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
+ sizer1->Add(_rbBrushTool, 1, wxGROW );
+
+ sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
+ sizer1->Add(txtBrushSize);
+ sizer1->Add(_sldBrushSize, 1, wxGROW );
+
sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
sizer1->Add(_rbBrushForm, 1, wxGROW );
+
+
sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
- sizer1->Add(_rbBrushTool, 1, wxGROW );
+ sizer1->Add(_txtToleranceFill);
+ sizer1->Add(_sldToleranceFill, 1, wxGROW );
+ sizer1->Add(_tolerancefillCtrl);
+
+ sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
+ sizer1->Add(_txtDistanceFill);
+ sizer1->Add(_sldDistanceFill, 1, wxGROW );
+ sizer1->Add(_distancefillCtrl);
+
+
sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
sizer1->Add(btnCopy, 1, wxGROW );
sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
}
}
+//---------------------------------------------------------------------------
+void wxManualPaintPanel::OnSldDistanceFill(wxScrollEvent& event)
+{
+ SetDistanceFill( (double)(_sldDistanceFill->GetValue()) );
+
+ wxString text;
+ text.Printf( wxT("%d"), _sldDistanceFill->GetValue() );
+ _distancefillCtrl->SetValue(text);
+}
+
+//---------------------------------------------------------------------------
+void wxManualPaintPanel::OnCtrTxtDistanceFill(wxCommandEvent &event)
+{
+ double distancefill;
+ wxString text=_distancefillCtrl->GetValue();
+ if (text.ToDouble(&distancefill))
+ {
+ SetDistanceFill( distancefill );
+ }
+}
+
+//---------------------------------------------------------------------------
+void wxManualPaintPanel::OnSldToleranceFill(wxScrollEvent& event)
+{
+ SetToleranceFill( (double)(_sldToleranceFill->GetValue()) );
+
+ wxString text;
+ text.Printf( wxT("%d"), _sldToleranceFill->GetValue() );
+ _tolerancefillCtrl->SetValue(text);
+}
+
+//---------------------------------------------------------------------------
+void wxManualPaintPanel::OnCtrTxtToleranceFill(wxCommandEvent &event)
+{
+ double tolerance;
+ wxString text=_tolerancefillCtrl->GetValue();
+ if (text.ToDouble(&tolerance))
+ {
+ SetToleranceFill( tolerance );
+ }
+}
+
+
+
+//---------------------------------------------------------------------------
+void wxManualPaintPanel::DisableControls()
+{
+ _sldBrushSize->Disable();
+ _rbBrushForm->Disable();
+
+ _txtToleranceFill->Disable();
+ _sldToleranceFill->Disable();
+ _tolerancefillCtrl->Disable();
+ _txtDistanceFill->Disable();
+ _sldDistanceFill->Disable();
+ _distancefillCtrl->Disable();
+}
//---------------------------------------------------------------------------
void wxManualPaintPanel::On2D3D(wxCommandEvent &event)
//---------------------------------------------------------------------------
void wxManualPaintPanel::OnBrushTool(wxCommandEvent &event)
{
+ DisableControls();
SetBrushTool( _rbBrushTool->GetSelection() );
+
+ if (_rbBrushTool->GetSelection()==0) //Brush tool
+ {
+ _sldBrushSize->Enable();
+ _rbBrushForm->Enable();
+ }
+
+ if (_rbBrushTool->GetSelection()==1) //Fill tool
+ {
+ _txtToleranceFill->Enable();
+ _sldToleranceFill->Enable();
+ _tolerancefillCtrl->Enable();
+
+ _txtDistanceFill->Enable();
+ _sldDistanceFill->Enable();
+ _distancefillCtrl->Enable();
+ }
}
//---------------------------------------------------------------------------