示例#1
0
void DataListCtrl::EndEdit(bool update)
{
	if (!m_rename_text->IsShown())
		return;

	if (update)
	{
		wxString new_name = m_rename_text->GetValue();

		long item = GetNextItem(-1,
			wxLIST_NEXT_ALL,
			wxLIST_STATE_SELECTED);
		VRenderFrame* vr_frame = (VRenderFrame*)m_frame;
		DataManager* mgr = vr_frame?vr_frame->GetDataManager():0;

		if (item != -1 && mgr)
		{
			wxString name = GetText(item, 1);

			if (new_name != name)
			{
				wxString new_name2 = new_name;
				for (int i=1; mgr->CheckNames(new_name2); i++)
					new_name2 = new_name+wxString::Format("_%d", i);


				if (GetItemText(item) == "Volume")
				{
					VolumeData* vd = mgr->GetVolumeData(name);
					if (vd)
						vd->SetName(new_name2);
				}
				else if (GetItemText(item) == "Mesh")
				{
					MeshData* md = mgr->GetMeshData(name);
					if (md)
						md->SetName(new_name2);
				}
				else if (GetItemText(item) == "Annotations")
				{
					Annotations* ann = mgr->GetAnnotations(name);
					if (ann)
						ann->SetName(new_name2);
				}

				//update ui
				SetText(item, 1, new_name2);
				vr_frame->UpdateTree();
			}
		}
	}

   m_rename_text->Hide();
}
示例#2
0
// Create new PDF file and append changed or new annotations
bool AnnotWriter::WriteTo(const char* name) {
	if (!CopyFile(name)) return false;
	if (!mAnnots.HasChanged()) return true;
	AssignShortFontNames();
	mFile = fopen(name, "a+b");
	bool ok = mFile != NULL;
	int numPages = mDoc->getNumPages();
	for (int i = 0; ok && i < numPages; i ++) {
		mPageRef = *mDoc->getCatalog()->getPageRef(i+1);
		Annotations* a = mAnnots.Get(i);
		if (a && a->HasChanged()) {
			Ref annotArray;
			ok = ok && UpdatePage(i, a, annotArray);
			ok = ok && UpdateAnnotArray(i, a, annotArray);
			for (int j = 0; ok && j < a->Length(); j ++) {
				Annotation* an = a->At(j);
				if (!an->IsDeleted()) {
					if (CanWrite(an)) {
						ok = UpdateAnnot(an);
					}
				} else {
					if (!is_empty_ref(an->GetRef())) {
						mXRefTable.DeleteRef(an->GetRef());
					}
				}
			}
		}
	}
	if (ok) {
		UpdateInfoDict();
		UpdateBePDFAcroForm();
		UpdateCatalog();
		ok = WriteXRefTable();
		ok = ok && WriteFileTrailer();
	}
	if (mFile) {
		fclose(mFile); mFile = NULL;
	}
	if (!ok) {
		// delete file on error
		unlink(name);
	}
	UnassignShortFontNames();
	return ok;
}
int main(int argc, char **argv)
{
  int n;
  
  // initialize project
  string projectName = "testProject"; 
// projectsRowdata prow( UNKNOWNID ,projectName, UNKNOWNID );
// projects.retrieveCreateByColumn( &prow, "name", projectName );
// long projectId = prow.get_id();

  for(n = 1; n < argc; n++) {
    Annotations * a = new Annotations(*(new string(argv[n])), NULL);

    for (procedures_map_cp p = a->procedures().begin();
	 p != a->procedures().end();
	 ++p)
      {
	procedureAnn * proc = p->second;

	cout << "procedure " << proc->name() << " (";

	for (var_list_cp p = proc->formal_params().begin();
	     p != proc->formal_params().end();
	     ++p)
	  {
	    annVariable * decl = *p;
	    if (p != proc->formal_params().begin())
	      cout << ", ";
	    cout << decl->name();
	  }
	cout << ")" << endl;
	cout << "{" << endl;

	cout << "  access { ";
	for (var_set_cp p = proc->uses().begin();
	     p != proc->uses().end();
	     ++p)
	  {
	    annVariable * decl = *p;
	    if (p != proc->uses().begin())
	      cout << ", ";
	    cout << decl->name();
	  }
	cout << "  }" << endl;
	
        int modifiedParams = 0;

	cout << "  modify { ";
	for (var_set_cp p = proc->defs().begin();
	     p != proc->defs().end();
	     ++p)
	  {
	    annVariable * decl = *p;
	    if (p != proc->defs().begin())
	      cout << ", ";
	    cout << decl->name();

            int found = -1;
            int pnum = 0;

	    for (var_list_cp fp = proc->formal_params().begin();
	       fp != proc->formal_params().end();
	       ++fp, ++pnum)
	    {
	       annVariable * param = *fp;
               if (param == decl) {
                  found = pnum;
                  modifiedParams++;
                  break;
               }
 	    }


          }

	cout << "  }" << endl;

	cout << "}" << endl;
	
      }

  //    a->print(cout);
//    delete a;
  }

  return( 0 );
}
示例#4
0
void DataListCtrl::OnSave(wxCommandEvent& event)
{
   long item = GetNextItem(-1,
         wxLIST_NEXT_ALL,
         wxLIST_STATE_SELECTED);
   if (item != -1)
   {
      wxString name = GetText(item, 1);

      if (GetItemText(item) == "Volume")
      {
         wxFileDialog *fopendlg = new wxFileDialog(
               m_frame, "Save Volume Data", "", "",
               "Muti-page Tiff file (*.tif, *.tiff)|*.tif;*.tiff|"\
               "Single-page Tiff sequence (*.tif)|*.tif;*.tiff|"\
               "Nrrd file (*.nrrd)|*.nrrd",
               wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
         fopendlg->SetExtraControlCreator(CreateExtraControl);

         int rval = fopendlg->ShowModal();

         if (rval == wxID_OK)
         {
             wxString filename = fopendlg->GetPath();

            VRenderFrame* vr_frame = (VRenderFrame*)m_frame;
            if (vr_frame)
            {
               VolumeData* vd = vr_frame->GetDataManager()->GetVolumeData(name);
               if (vd)
               {
                  vd->Save(filename, fopendlg->GetFilterIndex(), false, VRenderFrame::GetCompression());
                  wxString str = vd->GetPath();
                  SetText(item, 2, str);
               }
            }
         }
         delete fopendlg;
      }
      else if (GetItemText(item) == "Mesh")
      {
         wxFileDialog *fopendlg = new wxFileDialog(
               m_frame, "Save Mesh Data", "", "",
               "OBJ file (*.obj)|*.obj",
               wxFD_SAVE|wxFD_OVERWRITE_PROMPT);

         int rval = fopendlg->ShowModal();

         if (rval == wxID_OK)
         {
            wxString filename = fopendlg->GetPath();

            VRenderFrame* vr_frame = (VRenderFrame*)m_frame;
            if(vr_frame)
            {
               MeshData* md = vr_frame->GetDataManager()->GetMeshData(name);
               if (md)
               {
                  md->Save(filename);
                  wxString str = md->GetPath();
                  SetText(item, 2, str);
               }
            }
         }
         delete fopendlg;
      }
      else if (GetItemText(item) == "Annotations")
      {
         wxFileDialog *fopendlg = new wxFileDialog(
               m_frame, "Save Annotations", "", "",
               "Text file (*.txt)|*.txt",
               wxFD_SAVE|wxFD_OVERWRITE_PROMPT);

         int rval = fopendlg->ShowModal();

         if (rval == wxID_OK)
         {
            wxString filename = fopendlg->GetPath();

            VRenderFrame* vr_frame = (VRenderFrame*)m_frame;
            if(vr_frame)
            {
               Annotations* ann = vr_frame->GetDataManager()->GetAnnotations(name);
               if (ann)
               {
                  ann->Save(filename);
                  wxString str = ann->GetPath();
                  SetText(item, 2, str);
               }
            }
         }
         delete fopendlg;
      }
   }
}
示例#5
0
void DataListCtrl::OnContextMenu(wxContextMenuEvent &event )
{
   if (GetSelectedItemCount()>0)
   {
      wxPoint point = event.GetPosition();
      // If from keyboard
      if (point.x == -1 && point.y == -1)
      {
         wxSize size = GetSize();
         point.x = size.x / 2;
         point.y = size.y / 2;
      }
      else
      {
         point = ScreenToClient(point);
      }

      VRenderFrame* vr_frame = (VRenderFrame*)m_frame;

      if (vr_frame)
      {
         wxMenu menu;
         wxMenu *add_to_menu = new wxMenu;
         for (int i=0 ; i<(int)vr_frame->GetViewList()->size() ; i++)
         {
            add_to_menu->Append(Menu_View_start+i, (*vr_frame->GetViewList())[i]->GetName());
         }

         menu.Append(Menu_AddTo, "Add to", add_to_menu);
         if (GetSelectedItemCount()==1)
         {
            menu.Append(Menu_Del, "Delete");
            menu.Append(Menu_Rename, "Rename");
            //save/save as
            long item = GetNextItem(-1,
                  wxLIST_NEXT_ALL,
                  wxLIST_STATE_SELECTED);
            if (item!=-1)
            {
               if (GetItemText(item) == "Volume")
               {
                  wxString name = GetText(item, 1);
                  VolumeData* vd = vr_frame->GetDataManager()->GetVolumeData(name);
                  if (vd)
                  {
                     if (vd->GetPath() == "")
                        menu.Append(Menu_Save, "Save...");
                     else
                        menu.Append(Menu_Save, "Save As...");
                     menu.Append(Menu_Bake, "Bake...");
                  }
               }
               else if (GetItemText(item) == "Mesh")
               {
                  wxString name = GetText(item, 1);
                  MeshData* md = vr_frame->GetDataManager()->GetMeshData(name);
                  if (md)
                  {
                     if (md->GetPath() == "")
                        menu.Append(Menu_Save, "Save...");
                     else
                        menu.Append(Menu_Save, "Save As...");
                  }
               }
               else if (GetItemText(item) == "Annotations")
               {
                  wxString name = GetText(item, 1);
                  Annotations* ann = vr_frame->GetDataManager()->GetAnnotations(name);
                  if (ann)
                  {
                     if (ann->GetPath() == "")
                        menu.Append(Menu_Save, "Save...");
                     else
                        menu.Append(Menu_Save, "Save As...");
                  }
               }
            }
         }

         PopupMenu( &menu, point.x, point.y);
      }
   }
}
示例#6
0
pair<double,string> Classifier::getError(string trainingDirectory) {
    Annotations annotations;

    // read annotations
    string locationsFileName = trainingDirectory + "/" + Globals::annotationsFileName;
    annotations.readAnnotations(locationsFileName);

    // get the frames directory
    string framesDirectory = annotations.getFramesDirectory();

    double missclassified = 0;

    int counts[Globals::numZones];
    int missCounts[Globals::numZones];
    for (unsigned int i = 0; i < 3; i++) {
        counts[i] = 0;
        missCounts[i] = 0;
    }

    // iterate over the set of all annotations
    vector<FrameAnnotation*>& frameAnnotations = annotations.getFrameAnnotations();
    for (unsigned int i = 0; i < frameAnnotations.size(); i++) {
        FrameAnnotation* fa = frameAnnotations[i];

        int actualZone = fa->getZone();
        if (actualZone < 3)
            actualZone = 1;
        else if (actualZone > 3)
            actualZone = 3;
        else
            actualZone = 2;
        counts[actualZone - 1]++;

        // compose filename
        char buffer[256];
        sprintf(buffer, "frame_%d.png", fa->getFrameNumber());
        string fileName = framesDirectory + "/" + buffer;

        // load image
        IplImage* inputImg = cvLoadImage((const char*)fileName.c_str());

        double confidence;
        FrameAnnotation tf;
        int zone = getZone(inputImg, confidence, tf);
        if (zone < 3)
            zone = 1;
        else if (zone > 3)
            zone = 3;
        else
            zone = 2;

        if (zone != actualZone) {
            cout << "Classifier::getError. Expecting zone " << actualZone <<
                 " got zone " << zone << endl;
            missclassified++;
            missCounts[actualZone - 1]++;
        }

        cvReleaseImage(&inputImg);
    }

    int nAnnotations = frameAnnotations.size();
    char buffer[Globals::largeBufferSize];
    sprintf(buffer, "%d out of %d were miss-classified.", (int)missclassified, nAnnotations);
    string msg = buffer;
    sprintf(buffer, " Zones [%d, %d, %d].", counts[0], counts[1], counts[2]);
    msg += buffer;
    sprintf(buffer, " Missed [%d, %d, %d].", missCounts[0], missCounts[1], missCounts[2]);
    msg += buffer;

    return make_pair((missclassified / frameAnnotations.size()) * 100, msg);
}
示例#7
0
double Classifier::getFilterError(string trainingDirectory, Annotations::Tag tag,
                                  ErrorType errorType) {
    Annotations annotations;
    Filter* filter = getFilter(tag);

    // read annotations
    string locationsFileName = trainingDirectory + "/" + Globals::annotationsFileName;
    annotations.readAnnotations(locationsFileName);

    // get the frames directory
    string framesDirectory = annotations.getFramesDirectory();

    // reset total
    double totalError = 0;

    // iterate over the set of all annotations
    vector<FrameAnnotation*>& frameAnnotations = annotations.getFrameAnnotations();
    for (unsigned int i = 0; i < frameAnnotations.size(); i++) {
        FrameAnnotation* fa = frameAnnotations[i];

        // get LOI
        CvPoint& location = fa->getLOI(tag);
        if (!location.x && !location.y)
            continue;

        // compose filename
        char buffer[256];
        sprintf(buffer, "frame_%d.png", fa->getFrameNumber());
        string fileName = framesDirectory + "/" + buffer;

        // load image
        IplImage* inputImg = cvLoadImage((const char*)fileName.c_str());
        if (!inputImg) {
            string err = "Filter::update. Cannot load file " + fileName + ".";
            throw (err);
        }
        IplImage* image = cvCreateImage(cvGetSize(inputImg), IPL_DEPTH_8U, 1);
        cvCvtColor(inputImg, image, CV_BGR2GRAY);

        // get the location of the left eye
        CvPoint offset;
        offset.x = offset.y = 0;
        IplImage* roi = (roiFunction)? roiFunction(image, *fa, offset, Annotations::Face) : 0;

        location.x -= offset.x;
        location.y -= offset.y;

        // apply filter
        fftw_complex* imageFFT = filter->preprocessImage((roi)? roi : image);
        IplImage* postFilterImg = filter->apply(imageFFT);

        // compute location
        double min;
        double max;
        CvPoint minLoc;
        CvPoint maxLoc;
        cvMinMaxLoc(postFilterImg, &min, &max, &minLoc, &maxLoc);

        // compute squared error as the distance between the location
        // found and the location as annotated
        double xdiff = abs(maxLoc.x - location.x);
        double ydiff = abs(maxLoc.y - location.y);

        switch (errorType) {
        case OneNorm:
            totalError += (xdiff + ydiff);
            break;
        case TwoNorm:
            totalError += sqrt(xdiff * xdiff + ydiff * ydiff);
            break;
        case MSE:
            totalError += (xdiff * xdiff + ydiff * ydiff);
            break;
        default:
            totalError += ((xdiff > ydiff)? xdiff : ydiff);
            break;
        }

        if (roi)
            cvReleaseImage(&roi);
        cvReleaseImage(&image);
        cvReleaseImage(&inputImg);
    }

    return totalError / frameAnnotations.size();
}
示例#8
0
int main(int argc, char** argv) {
  string modelsFileName = "";
  string imageFileName = "";
  string imageDirectory = "";
  int x = Globals::imgWidth / 2;
  int y = Globals::imgHeight / 2;

  for (int i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-i"))
      imageFileName = argv[i + 1];
    else if (!strcmp(argv[i], "-d"))
      imageDirectory = argv[i + 1];
    else if (!strcmp(argv[i], "-m"))
      modelsFileName = argv[i + 1];
    else if (!strcmp(argv[i], "-c")) {
      char* str = argv[i + 1];
      char* token = strtok(str, "(),");
      if (token)
	x = atoi(token);
      token = strtok(NULL, "(),");
      if (token)
	y = atoi(token);
    }
    else if (!strcmp(argv[i], "-h")) {
      cout << 
	"Usage: classify -i <imageFileName> -m <modelsFileName>" << endl;
      return 0;
    }
  }

  if (modelsFileName == "") {
    cout << 
      "Usage: classify -i <imageFileName> -m <modelsFileName>" << endl;
    return -1;
  }

  CvPoint center;
  center.x = x;
  center.y = y;

  CvSize size;
  size.width = Globals::roiWidth;
  size.height = Globals::roiHeight;

  double scale = 0.3;

  try {
    loadModel(modelsFileName);

    if (imageFileName != "") {
      Preprocess preprocess(size, scale, center, roiFunction);
      IplImage* image = cvLoadImage(imageFileName.c_str());
      IplImage* imageVector = preprocess.generateImageVector(image);

      cout << "Sector " << classify(imageVector) << endl;
      cvReleaseImage(&image);
      cvReleaseImage(&imageVector);
    } else if (imageDirectory != "") {
      int counts[5][6];
      for (int i = 0; i < 5; i++)
	for (int j = 0; j < 6; j++)
	  counts[i][j] = 0;

      string annotationsFileName = imageDirectory + "/annotations.xml";
      Annotations annotations;
      annotations.readAnnotations(annotationsFileName);
      CvPoint& center = annotations.getCenter();

      Preprocess preprocess(size, scale, center, roiFunction);
      vector<FrameAnnotation*>& frameAnnotations = annotations.getFrameAnnotations();
      for (unsigned int i = 0; i < frameAnnotations.size(); i++) {
	FrameAnnotation* fa = frameAnnotations[i];
	fa->setFace(center);

	int expectedZone = fa->getSector();
	counts[expectedZone - 1][5]++;

	// compose filename and update map
	char buffer[256];
	sprintf(buffer, "frame_%d.png", fa->getFrameNumber());
	string simpleName = buffer;
	string fileName = imageDirectory + "/" + simpleName;
	IplImage* image = cvLoadImage(fileName.c_str());
	IplImage* imageVector = preprocess.generateImageVector(image);

	int zone = classify(imageVector);
	if (expectedZone == zone)
	  counts[zone - 1][zone - 1]++;
	else
	  counts[expectedZone - 1][zone - 1]++;

	cvReleaseImage(&image);
	cvReleaseImage(&imageVector);
      }
      cout << "Errors by class" << endl;
      for (int i = 0; i < 5; i++) {
	for (int j = 0; j < 6; j++)
	  cout << counts[i][j] << "\t";
	cout << endl;
      }
    }
  } catch (string err) {
    cout << err << endl;
  }

  return 0;
}