+ }
+}
+
+void
+ImageFileView::OnScaleSize (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ unsigned int iOldNX = rIF.nx();
+ unsigned int iOldNY = rIF.ny();
+
+ DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
+ if (dialogGetXYSize.ShowModal() == wxID_OK) {
+ unsigned int iNewNX = dialogGetXYSize.getXSize();
+ unsigned int iNewNY = dialogGetXYSize.getYSize();
+ std::ostringstream os;
+ os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
+ ImageFileDocument* pScaledDoc = theApp->newImageDoc();
+ if (! pScaledDoc) {
+ sys_error (ERR_SEVERE, "Unable to create image file");
+ return;
+ }
+ ImageFile& rScaledIF = pScaledDoc->getImageFile();
+ rScaledIF.setArraySize (iNewNX, iNewNY);
+ rScaledIF.labelsCopy (rIF);
+ rScaledIF.labelAdd (os.str().c_str());
+ rIF.scaleImage (rScaledIF);
+ *theApp->getLog() << os.str().c_str() << "\n";
+ if (theApp->getSetModifyNewDocs())
+ pScaledDoc->Modify(TRUE);
+ pScaledDoc->UpdateAllViews (this);
+ pScaledDoc->getView()->OnUpdate (this, NULL);
+ pScaledDoc->getView()->getFrame()->Show(true);
+ }
+}
+
+void
+ImageFileView::OnPlotRow (wxCommandEvent& event)
+{
+ int xCursor, yCursor;
+ if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
+ wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
+ return;
+ }
+
+ const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
+ ImageFileArrayConst v = rIF.getArray();
+ ImageFileArrayConst vImag = rIF.getImaginaryArray();
+ int nx = rIF.nx();
+ int ny = rIF.ny();
+
+ if (v != NULL && yCursor < ny) {
+ double* pX = new double [nx];
+ double* pYReal = new double [nx];
+ double *pYImag = NULL;
+ double *pYMag = NULL;
+ if (rIF.isComplex()) {
+ pYImag = new double [nx];
+ pYMag = new double [nx];
+ }
+ for (int i = 0; i < nx; i++) {
+ pX[i] = i;
+ pYReal[i] = v[i][yCursor];
+ if (rIF.isComplex()) {
+ pYImag[i] = vImag[i][yCursor];
+ pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
+ }
+ }
+ PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
+ if (! pPlotDoc) {
+ sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
+ } else {
+ PlotFile& rPlotFile = pPlotDoc->getPlotFile();
+ std::ostringstream os;
+ os << "Row " << yCursor;
+ std::string title("title ");
+ title += os.str();
+ rPlotFile.addEzsetCommand (title.c_str());
+ rPlotFile.addEzsetCommand ("xlabel Column");
+ rPlotFile.addEzsetCommand ("ylabel Pixel Value");
+ rPlotFile.addEzsetCommand ("lxfrac 0");
+ rPlotFile.addEzsetCommand ("box");
+ rPlotFile.addEzsetCommand ("grid");
+ rPlotFile.addEzsetCommand ("curve 1");
+ rPlotFile.addEzsetCommand ("color 1");
+ if (rIF.isComplex()) {
+ rPlotFile.addEzsetCommand ("dash 1");
+ rPlotFile.addEzsetCommand ("curve 2");
+ rPlotFile.addEzsetCommand ("color 4");
+ rPlotFile.addEzsetCommand ("dash 3");
+ rPlotFile.addEzsetCommand ("curve 3");
+ rPlotFile.addEzsetCommand ("color 0");
+ rPlotFile.addEzsetCommand ("solid");
+ rPlotFile.setCurveSize (4, nx);
+ } else
+ rPlotFile.setCurveSize (2, nx);
+ rPlotFile.addColumn (0, pX);
+ rPlotFile.addColumn (1, pYReal);
+ if (rIF.isComplex()) {
+ rPlotFile.addColumn (2, pYImag);
+ rPlotFile.addColumn (3, pYMag);
+ }
+ for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
+ rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
+ os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
+ *theApp->getLog() << os.str().c_str() << "\n";
+ rPlotFile.addDescription (os.str().c_str());
+ }
+ delete pX;
+ delete pYReal;
+ if (rIF.isComplex()) {
+ delete pYImag;
+ delete pYMag;
+ }
+ if (theApp->getSetModifyNewDocs())
+ pPlotDoc->Modify(true);
+ pPlotDoc->UpdateAllViews();
+ }
+}
+
+void
+ImageFileView::OnPlotCol (wxCommandEvent& event)
+{
+ int xCursor, yCursor;
+ if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
+ wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
+ return;
+ }
+
+ const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
+ ImageFileArrayConst v = rIF.getArray();
+ ImageFileArrayConst vImag = rIF.getImaginaryArray();
+ int nx = rIF.nx();
+ int ny = rIF.ny();
+
+ if (v != NULL && xCursor < nx) {
+ double* pX = new double [ny];
+ double* pYReal = new double [ny];
+ double* pYImag = NULL;
+ double* pYMag = NULL;
+ if (rIF.isComplex()) {
+ pYImag = new double [ny];
+ pYMag = new double [ny];
+ }
+ for (int i = 0; i < ny; i++) {
+ pX[i] = i;
+ pYReal[i] = v[xCursor][i];
+ if (rIF.isComplex()) {
+ pYImag[i] = vImag[xCursor][i];
+ pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
+ }
+ }
+ PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
+ if (! pPlotDoc) {
+ sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
+ } else {
+ PlotFile& rPlotFile = pPlotDoc->getPlotFile();
+ std::ostringstream os;
+ os << "Column " << xCursor;
+ std::string title("title ");
+ title += os.str();
+ rPlotFile.addEzsetCommand (title.c_str());
+ rPlotFile.addEzsetCommand ("xlabel Row");
+ rPlotFile.addEzsetCommand ("ylabel Pixel Value");
+ rPlotFile.addEzsetCommand ("lxfrac 0");
+ rPlotFile.addEzsetCommand ("box");
+ rPlotFile.addEzsetCommand ("grid");
+ rPlotFile.addEzsetCommand ("curve 1");
+ rPlotFile.addEzsetCommand ("color 1");
+ if (rIF.isComplex()) {
+ rPlotFile.addEzsetCommand ("dash 1");
+ rPlotFile.addEzsetCommand ("curve 2");
+ rPlotFile.addEzsetCommand ("color 4");
+ rPlotFile.addEzsetCommand ("dash 3");
+ rPlotFile.addEzsetCommand ("curve 3");
+ rPlotFile.addEzsetCommand ("color 0");
+ rPlotFile.addEzsetCommand ("solid");
+ rPlotFile.setCurveSize (4, ny);
+ } else
+ rPlotFile.setCurveSize (2, ny);
+ rPlotFile.addColumn (0, pX);
+ rPlotFile.addColumn (1, pYReal);
+ if (rIF.isComplex()) {
+ rPlotFile.addColumn (2, pYImag);
+ rPlotFile.addColumn (3, pYMag);
+ }
+ for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
+ rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
+ os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
+ *theApp->getLog() << os.str().c_str() << "\n";
+ rPlotFile.addDescription (os.str().c_str());
+ }
+ delete pX;
+ delete pYReal;
+ if (rIF.isComplex()) {
+ delete pYImag;
+ delete pYMag;
+ }
+ if (theApp->getSetModifyNewDocs())
+ pPlotDoc->Modify(true);
+ pPlotDoc->UpdateAllViews();
+ }
+}
+
+#ifdef HAVE_FFT
+void
+ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
+{
+ int xCursor, yCursor;
+ if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
+ wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
+ return;
+ }
+
+ const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
+ ImageFileArrayConst v = rIF.getArray();
+ ImageFileArrayConst vImag = rIF.getImaginaryArray();
+ int nx = rIF.nx();
+ int ny = rIF.ny();
+
+ if (v != NULL && yCursor < ny) {
+ fftw_complex* pcIn = new fftw_complex [nx];
+
+ int i;
+ for (i = 0; i < nx; i++) {
+ pcIn[i].re = v[i][yCursor];
+ if (rIF.isComplex())
+ pcIn[i].im = vImag[i][yCursor];
+ else
+ pcIn[i].im = 0;
+ }
+
+ fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
+ fftw_one (plan, pcIn, NULL);
+ fftw_destroy_plan (plan);
+
+ double* pX = new double [nx];
+ double* pYReal = new double [nx];
+ double* pYImag = new double [nx];
+ double* pYMag = new double [nx];
+ for (i = 0; i < nx; i++) {
+ pX[i] = i;
+ pYReal[i] = pcIn[i].re;
+ pYImag[i] = pcIn[i].im;
+ pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
+ }
+ Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
+ Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
+ Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
+
+ PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
+ if (! pPlotDoc) {
+ sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
+ } else {
+ PlotFile& rPlotFile = pPlotDoc->getPlotFile();
+ std::ostringstream os;
+ os << "Row " << yCursor;
+ std::string title("title ");
+ title += os.str();
+ rPlotFile.addEzsetCommand (title.c_str());
+ rPlotFile.addEzsetCommand ("xlabel Column");
+ rPlotFile.addEzsetCommand ("ylabel Pixel Value");
+ rPlotFile.addEzsetCommand ("lxfrac 0");
+ rPlotFile.addEzsetCommand ("curve 1");
+ rPlotFile.addEzsetCommand ("color 1");
+ rPlotFile.addEzsetCommand ("dash 1");
+ rPlotFile.addEzsetCommand ("curve 2");
+ rPlotFile.addEzsetCommand ("color 4");
+ rPlotFile.addEzsetCommand ("dash 3");
+ rPlotFile.addEzsetCommand ("curve 3");
+ rPlotFile.addEzsetCommand ("color 0");
+ rPlotFile.addEzsetCommand ("solid");
+ rPlotFile.addEzsetCommand ("box");
+ rPlotFile.addEzsetCommand ("grid");
+ rPlotFile.setCurveSize (4, nx);
+ rPlotFile.addColumn (0, pX);
+ rPlotFile.addColumn (1, pYReal);
+ rPlotFile.addColumn (2, pYImag);
+ rPlotFile.addColumn (3, pYMag);
+ for (int iL = 0; iL < rIF.nLabels(); iL++)
+ rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
+ os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
+ *theApp->getLog() << os.str().c_str() << "\n";
+ rPlotFile.addDescription (os.str().c_str());
+ }
+ delete pX;
+ delete pYReal;
+ delete pYImag;
+ delete pYMag;
+ delete [] pcIn;
+
+ if (theApp->getSetModifyNewDocs())
+ pPlotDoc->Modify(true);
+ pPlotDoc->UpdateAllViews();
+ }
+}
+
+void
+ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
+{
+ int xCursor, yCursor;
+ if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
+ wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
+ return;
+ }
+
+ const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
+ ImageFileArrayConst v = rIF.getArray();
+ ImageFileArrayConst vImag = rIF.getImaginaryArray();
+ int nx = rIF.nx();
+ int ny = rIF.ny();
+
+ if (v != NULL && xCursor < nx) {
+ fftw_complex* pcIn = new fftw_complex [ny];
+ double *pdTemp = new double [ny];
+
+ int i;
+ for (i = 0; i < ny; i++)
+ pdTemp[i] = v[xCursor][i];
+ Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
+ for (i = 0; i < ny; i++)
+ pcIn[i].re = pdTemp[i];
+
+ for (i = 0; i < ny; i++) {
+ if (rIF.isComplex())
+ pdTemp[i] = vImag[xCursor][i];
+ else
+ pdTemp[i] = 0;
+ }
+ Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
+ for (i = 0; i < ny; i++)
+ pcIn[i].im = pdTemp[i];
+
+ fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
+ fftw_one (plan, pcIn, NULL);
+ fftw_destroy_plan (plan);
+
+ double* pX = new double [ny];
+ double* pYReal = new double [ny];
+ double* pYImag = new double [ny];
+ double* pYMag = new double [ny];
+ for (i = 0; i < ny; i++) {
+ pX[i] = i;
+ pYReal[i] = pcIn[i].re;
+ pYImag[i] = pcIn[i].im;
+ pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
+ }
+
+ PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
+ if (! pPlotDoc) {
+ sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
+ } else {
+ PlotFile& rPlotFile = pPlotDoc->getPlotFile();
+ std::ostringstream os;
+ os << "Column " << xCursor;
+ std::string title("title ");
+ title += os.str();
+ rPlotFile.addEzsetCommand (title.c_str());
+ rPlotFile.addEzsetCommand ("xlabel Column");
+ rPlotFile.addEzsetCommand ("ylabel Pixel Value");
+ rPlotFile.addEzsetCommand ("lxfrac 0");
+ rPlotFile.addEzsetCommand ("curve 1");
+ rPlotFile.addEzsetCommand ("color 1");
+ rPlotFile.addEzsetCommand ("dash 1");
+ rPlotFile.addEzsetCommand ("curve 2");
+ rPlotFile.addEzsetCommand ("color 4");
+ rPlotFile.addEzsetCommand ("dash 3");
+ rPlotFile.addEzsetCommand ("curve 3");
+ rPlotFile.addEzsetCommand ("color 0");
+ rPlotFile.addEzsetCommand ("solid");
+ rPlotFile.addEzsetCommand ("box");
+ rPlotFile.addEzsetCommand ("grid");
+ rPlotFile.setCurveSize (4, ny);
+ rPlotFile.addColumn (0, pX);
+ rPlotFile.addColumn (1, pYReal);
+ rPlotFile.addColumn (2, pYImag);
+ rPlotFile.addColumn (3, pYMag);
+ for (int iL = 0; iL < rIF.nLabels(); iL++)
+ rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
+ os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
+ *theApp->getLog() << os.str().c_str() << "\n";
+ rPlotFile.addDescription (os.str().c_str());
+ }
+ delete pX;
+ delete pYReal;
+ delete pYImag;
+ delete pYMag;
+ delete pdTemp;
+ delete [] pcIn;
+
+ if (theApp->getSetModifyNewDocs())
+ pPlotDoc->Modify(true);
+ pPlotDoc->UpdateAllViews();
+ }
+}
+#endif
+
+void
+ImageFileView::OnCompareCol (wxCommandEvent& event)
+{
+ int xCursor, yCursor;
+ if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
+ wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
+ return;
+ }
+
+ std::vector<ImageFileDocument*> vecIFDoc;
+ theApp->getCompatibleImages (GetDocument(), vecIFDoc);
+ if (vecIFDoc.size() == 0) {
+ wxMessageBox ("No compatible images for Column Comparison", "Error");
+ return;
+ }
+ DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
+
+ if (dialogGetCompare.ShowModal() == wxID_OK) {
+ ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
+ const ImageFile& rIF = GetDocument()->getImageFile();
+ const ImageFile& rCompareIF = pCompareDoc->getImageFile();
+
+ ImageFileArrayConst v1 = rIF.getArray();
+ ImageFileArrayConst v2 = rCompareIF.getArray();
+ int nx = rIF.nx();
+ int ny = rIF.ny();
+
+ if (v1 != NULL && xCursor < nx) {
+ double* pX = new double [ny];
+ double* pY1 = new double [ny];
+ double* pY2 = new double [ny];
+ for (int i = 0; i < ny; i++) {
+ pX[i] = i;
+ pY1[i] = v1[xCursor][i];
+ pY2[i] = v2[xCursor][i];
+ }
+ PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
+ if (! pPlotDoc) {
+ sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
+ } else {
+ PlotFile& rPlotFile = pPlotDoc->getPlotFile();
+ std::ostringstream os;
+ os << "Column " << xCursor << " Comparison";
+ std::string title("title ");
+ title += os.str();
+ rPlotFile.addEzsetCommand (title.c_str());
+ rPlotFile.addEzsetCommand ("xlabel Row");
+ rPlotFile.addEzsetCommand ("ylabel Pixel Value");
+ rPlotFile.addEzsetCommand ("lxfrac 0");
+ rPlotFile.addEzsetCommand ("curve 1");
+ rPlotFile.addEzsetCommand ("color 2");
+ rPlotFile.addEzsetCommand ("curve 2");
+ rPlotFile.addEzsetCommand ("color 4");
+ rPlotFile.addEzsetCommand ("dash 5");
+ rPlotFile.addEzsetCommand ("box");
+ rPlotFile.addEzsetCommand ("grid");
+ rPlotFile.setCurveSize (3, ny);
+ rPlotFile.addColumn (0, pX);
+ rPlotFile.addColumn (1, pY1);
+ rPlotFile.addColumn (2, pY2);
+
+ unsigned int iL;
+ for (iL = 0; iL < rIF.nLabels(); iL++) {
+ std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
+ s += ": ";
+ s += rIF.labelGet(iL).getLabelString();
+ rPlotFile.addDescription (s.c_str());
+ }
+ for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
+ std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
+ s += ": ";
+ s += rCompareIF.labelGet(iL).getLabelString();
+ rPlotFile.addDescription (s.c_str());
+ }
+ os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
+ << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
+ *theApp->getLog() << os.str().c_str() << "\n";
+ rPlotFile.addDescription (os.str().c_str());
+ }
+ delete pX;
+ delete pY1;
+ delete pY2;
+ if (theApp->getSetModifyNewDocs())
+ pPlotDoc->Modify(true);
+ pPlotDoc->UpdateAllViews();
+ }
+ }
+}
+
+void
+ImageFileView::OnCompareRow (wxCommandEvent& event)
+{
+ int xCursor, yCursor;
+ if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
+ wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
+ return;
+ }
+
+ std::vector<ImageFileDocument*> vecIFDoc;
+ theApp->getCompatibleImages (GetDocument(), vecIFDoc);
+
+ if (vecIFDoc.size() == 0) {
+ wxMessageBox ("No compatible images for Row Comparison", "Error");
+ return;
+ }
+
+ DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
+
+ if (dialogGetCompare.ShowModal() == wxID_OK) {
+ ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
+ const ImageFile& rIF = GetDocument()->getImageFile();
+ const ImageFile& rCompareIF = pCompareDoc->getImageFile();
+
+ ImageFileArrayConst v1 = rIF.getArray();
+ ImageFileArrayConst v2 = rCompareIF.getArray();
+ int nx = rIF.nx();
+ int ny = rIF.ny();
+
+ if (v1 != NULL && yCursor < ny) {
+ double* pX = new double [nx];
+ double* pY1 = new double [nx];
+ double* pY2 = new double [nx];
+ for (int i = 0; i < nx; i++) {
+ pX[i] = i;
+ pY1[i] = v1[i][yCursor];
+ pY2[i] = v2[i][yCursor];
+ }
+ PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
+ if (! pPlotDoc) {
+ sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
+ } else {
+ PlotFile& rPlotFile = pPlotDoc->getPlotFile();
+ std::ostringstream os;
+ os << "Row " << yCursor << " Comparison";
+ std::string title("title ");
+ title += os.str();
+ rPlotFile.addEzsetCommand (title.c_str());
+ rPlotFile.addEzsetCommand ("xlabel Column");
+ rPlotFile.addEzsetCommand ("ylabel Pixel Value");
+ rPlotFile.addEzsetCommand ("lxfrac 0");
+ rPlotFile.addEzsetCommand ("curve 1");
+ rPlotFile.addEzsetCommand ("color 2");
+ rPlotFile.addEzsetCommand ("curve 2");
+ rPlotFile.addEzsetCommand ("color 4");
+ rPlotFile.addEzsetCommand ("dash 5");
+ rPlotFile.addEzsetCommand ("box");
+ rPlotFile.addEzsetCommand ("grid");
+ rPlotFile.setCurveSize (3, nx);
+ rPlotFile.addColumn (0, pX);
+ rPlotFile.addColumn (1, pY1);
+ rPlotFile.addColumn (2, pY2);
+ unsigned int iL;
+ for (iL = 0; iL < rIF.nLabels(); iL++) {
+ std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
+ s += ": ";
+ s += rIF.labelGet(iL).getLabelString();
+ rPlotFile.addDescription (s.c_str());
+ }
+ for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
+ std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
+ s += ": ";
+ s += rCompareIF.labelGet(iL).getLabelString();
+ rPlotFile.addDescription (s.c_str());
+ }
+ os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
+ << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
+ *theApp->getLog() << os.str().c_str() << "\n";
+ rPlotFile.addDescription (os.str().c_str());
+ }
+ delete pX;
+ delete pY1;
+ delete pY2;
+ if (theApp->getSetModifyNewDocs())
+ pPlotDoc->Modify(true);
+ pPlotDoc->UpdateAllViews();
+ }
+ }
+}
+
+static int NUMBER_HISTOGRAM_BINS = 256;
+
+void
+ImageFileView::OnPlotHistogram (wxCommandEvent& event)
+{
+ const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
+ ImageFileArrayConst v = rIF.getArray();
+ int nx = rIF.nx();
+ int ny = rIF.ny();
+
+ if (v != NULL && nx > 0 && ny > 0) {
+ PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
+ if (! pPlotDoc) {
+ sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
+ return;
+ }
+
+ double* pX = new double [NUMBER_HISTOGRAM_BINS];
+ double* pY = new double [NUMBER_HISTOGRAM_BINS];
+ double dMin, dMax;
+ rIF.getMinMax (dMin, dMax);
+ double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
+
+ for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
+ pX[i] = dMin + (i + 0.5) * dBinWidth;
+ pY[i] = 0;
+ }
+ for (int ix = 0; ix < nx; ix++)
+ for (int iy = 0; iy < ny; iy++) {
+ int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
+ if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
+ pY[iBin] += 1;
+ }
+
+ PlotFile& rPlotFile = pPlotDoc->getPlotFile();
+ std::ostringstream os;
+ os << "Histogram";
+ std::string title("title ");
+ title += os.str();
+ rPlotFile.addEzsetCommand (title.c_str());
+ rPlotFile.addEzsetCommand ("xlabel Pixel Value");
+ rPlotFile.addEzsetCommand ("ylabel Count");
+ rPlotFile.addEzsetCommand ("box");
+ rPlotFile.addEzsetCommand ("grid");
+ rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
+ rPlotFile.addColumn (0, pX);
+ rPlotFile.addColumn (1, pY);
+ for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
+ std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
+ s += ": ";
+ s += rIF.labelGet(iL).getLabelString();
+ rPlotFile.addDescription (s.c_str());
+ }
+ os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
+ *theApp->getLog() << os.str().c_str() << "\n";
+ rPlotFile.addDescription (os.str().c_str());
+ delete pX;
+ delete pY;
+ if (theApp->getSetModifyNewDocs())
+ pPlotDoc->Modify(true);
+ pPlotDoc->UpdateAllViews();
+ }