示例#1
0
void testApp::guiEvent(ofxUIEventArgs &e)
{
	string widgetName = e.widget->getName();
	if(widgetName == "Capture"){
		if(((ofxUILabelButton*) e.widget)->getValue()) {
#ifndef __APPLE__
#ifndef __NO_KINECT__
			ofLogNotice() << "Capturing Depth Image";
			ofSaveImage(kinect.getPixelsRef(), "capture/" + ofGetTimestampString() + ".jpg", OF_IMAGE_QUALITY_BEST);
			c.saveToRaw("capture/" + ofGetTimestampString() + ".raw", kinect.getRawDepthPixels());
			c.saveToCompressedPng("capture/" + ofGetTimestampString() + ".png", kinect.getRawDepthPixels());
			saveMesh();
#endif
#endif
		}
	}
}
示例#2
0
文件: converter.cpp 项目: 2php/pcl
/**
 * Saves a cloud into the specified file and output type. The file format is automatically parsed.
 * @param input[in] The cloud to be saved
 * @param output_file[out] The output file to be written
 * @param output_type[in] The output file type
 * @return True on success, false otherwise.
 */
bool
savePointCloud (pcl::PCLPointCloud2::Ptr input,
                std::string output_file,
                int output_type)
{
  if (boost::filesystem::path (output_file).extension () == ".pcd")
  {
    //TODO Support precision, origin, orientation
    pcl::PCDWriter w;
    if (output_type == ASCII)
    {
      PCL_INFO ("Saving file %s as ASCII.\n", output_file.c_str ());
      if (w.writeASCII (output_file, *input) != 0)
        return (false);
    }
    else if (output_type == BINARY)
    {
      PCL_INFO ("Saving file %s as binary.\n", output_file.c_str ());
      if (w.writeBinary (output_file, *input) != 0)
        return (false);
    }
    else if (output_type == BINARY_COMPRESSED)
    {
      PCL_INFO ("Saving file %s as binary compressed.\n", output_file.c_str ());
      if (w.writeBinaryCompressed (output_file, *input) != 0)
        return (false);
    }
  }
  else if (boost::filesystem::path (output_file).extension () == ".stl")
  {
    PCL_ERROR ("STL file format does not support point clouds! Aborting.\n");
    return (false);
  }
  else  // OBJ, PLY and VTK
  {
    //TODO: Support precision
    //FIXME: Color is lost during OBJ conversion (OBJ supports color)
    pcl::PolygonMesh mesh;
    mesh.cloud = *input;
    if (!saveMesh (mesh, output_file, output_type))
      return (false);
  }

  return (true);
}
void TriangularMeshWriterService::updating() throw(::fwTools::Failed)
{
    SLM_TRACE_FUNC();

    if( this->hasLocationDefined() )
    {
        // Retrieve dataStruct associated with this service
        ::fwData::TriangularMesh::sptr pTriangularMesh = this->getObject< ::fwData::TriangularMesh >() ;
        SLM_ASSERT("pTriangularMesh not instanced", pTriangularMesh);

        ::fwGui::Cursor cursor;
        cursor.setCursor(::fwGui::ICursor::BUSY);

        saveMesh( this->getFile(), pTriangularMesh);

        cursor.setDefaultCursor();
    }
}
示例#4
0
KawaiiGL::KawaiiGL(QWidget *parent)
    : QMainWindow(parent), m_kView(NULL), m_edDlg(NULL), m_doc(NULL)
{
    ui.setupUi(this);

    m_sett.loadFromReg();
    connect(&m_sett, SIGNAL(changed()), &m_sett, SLOT(storeToReg()));

    setWindowTitle("KawaiiGL");
    show(); // needed becase we're creating display lists in the c'tor.

    QDir::setCurrent(EXAMPLES_DIR); // we're reading the config and textures from there

    m_progMenu = new QMenu(this);
    m_modelsMenu = new QMenu(this);

    m_doc = new Document(this); // adds to the menus

    m_progMenu->addSeparator();
    QAction *loadFromFileAct = m_progMenu->addAction("From file...");
    connect(loadFromFileAct, SIGNAL(triggered(bool)), m_doc, SLOT(loadProgramFile()));

    m_kView = new T2GLWidget(this, m_doc);
    setCentralWidget(m_kView);

    m_edDlg = new KwEdit(this, m_sett.disp, m_doc, m_kView); // need the view for tracking vec2s
    m_edDlg->show();
    m_edDlg->move(pos() + QPoint(width() - 20, 30));

    m_control = new MyDialog(this);
    QBoxLayout *control_l = new QVBoxLayout();
    m_control->setLayout(control_l);
    control_l->setMargin(0);
    control_l->setSpacing(0);
    QTabWidget *tabs = new QTabWidget();
    control_l->addWidget(tabs);

    m_contDlg = new ControlPanel(&m_sett.disp, this, m_doc, m_kView);
    tabs->addTab(m_contDlg, "Config");
    m_browse = new ProjBrowser(this, m_doc);
    tabs->addTab(m_browse, "Browser");
    tabs->setCurrentWidget(m_browse);

    //tabs->setCurrentIndex(m_sett.gui.configWindowTab);
    tabs->setCurrentIndex(0);

    m_control->show();
    m_control->move(pos() + QPoint(-30, 20));
    m_control->resize(100, 100); // make it as small as possible

    m_doc->model()->m_errAct = new ErrorHighlight(m_edDlg);

    connect(m_kView, SIGNAL(message(const QString&)), this, SLOT(message(const QString&)));

    connect(m_edDlg, SIGNAL(changedModel(DocSrc*)), m_doc, SLOT(calc(DocSrc*)));
    connect(m_edDlg, SIGNAL(updateShaders()), m_doc, SLOT(compileShaders()));

//	connect(m_kView, SIGNAL(decompProgChanged(const QString&)), m_edDlg, SLOT(curChanged(const QString&)));

    connect(m_doc, SIGNAL(loaded()), m_kView, SLOT(newModelLoaded()));
    //connect(m_doc, SIGNAL(loaded()), m_edDlg, SLOT(doVarsUpdate())); // parsed new text. vars defs may be wrong
    connect(m_doc, SIGNAL(modelChanged()), m_kView, SLOT(updateGL()));
    connect(m_doc, SIGNAL(progChanged()), m_kView, SLOT(redoFrameBuffers()));
    connect(m_kView, SIGNAL(changedFBOs()), m_contDlg, SLOT(updateTexEdits()));
    connect(m_kView, SIGNAL(makeGradientTex(int, const QString&)), m_contDlg, SLOT(externalGradient(int, const QString&)));

    connect(m_doc, SIGNAL(progParamChanged()), m_kView, SLOT(updateGL()));
    connect(m_doc, SIGNAL(addModelLine(const QString&)), m_edDlg, SLOT(addModelLine(const QString&)));

    connect(m_contDlg, SIGNAL(changedRend()), m_doc, SLOT(calcNoParse())); // passes update
    connect(m_contDlg, SIGNAL(changedFont()), m_kView, SLOT(updateCoordFont()));
    connect(m_contDlg, SIGNAL(doUpdate()), m_kView, SLOT(updateGL())); // passes update

    connect(m_contDlg, SIGNAL(resetView()), m_kView, SLOT(resetState()));
    connect(m_contDlg, SIGNAL(resetLight()), m_kView, SLOT(resetLight()));
    connect(m_contDlg, SIGNAL(changedTexFile(int)), m_kView, SLOT(setTexture(int)));
//	connect(m_contDlg, SIGNAL(reassertTex(int)), m_kView, SLOT(rebindTexture(int)));
    connect(m_contDlg, SIGNAL(saveMesh()), m_doc, SLOT(calcSave()));

    connect(m_browse, SIGNAL(openDocText(DocElement*)), m_edDlg, SLOT(addPage(DocElement*)) );
    connect(m_browse, SIGNAL(openPassConf(DocElement*)), m_edDlg, SLOT(addPage(DocElement*)) );
    connect(m_browse, SIGNAL(commitGuiData()), m_edDlg, SLOT(commitAll()));

    connect(m_doc, SIGNAL(goingToClearProg()), m_edDlg, SLOT(clearingProg()));
    connect(m_doc, SIGNAL(didReadProg(ProgKeep*)), m_edDlg, SLOT(readProg(ProgKeep*)) );
    connect(m_doc, SIGNAL(didReadProg(ProgKeep*)), m_browse, SLOT(readProg(ProgKeep*)) );
    connect(m_doc, SIGNAL(didReadModel(DocSrc*)), m_browse, SLOT(readModel()) );
    connect(m_doc, SIGNAL(didReadModel(DocSrc*)), m_edDlg, SLOT(readModel(DocSrc*)));

    connect(&m_sett.disp.bVtxNormals, SIGNAL(changed()), m_doc, SLOT(calcNoParse())); // TBD - this is bad.

    connect(m_contDlg->ui.clipSlider, SIGNAL(valueChanged(int)), m_kView, SLOT(setClipValue(int)));

    m_kView->setContextMenuPolicy(Qt::ActionsContextMenu);

    QPushButton *viewBot = new QPushButton("View");
    viewBot->setMaximumSize(60, 19);
    statusBar()->addPermanentWidget(viewBot);
    QMenu *view = new QMenu("View");
    viewBot->setMenu(view);

    QPushButton *fpsBot = new QPushButton(QIcon(":/images/arrow-circle.png"), QString());
    fpsBot->setMaximumSize(20, 19);
    statusBar()->addPermanentWidget(fpsBot);
    (new CheckBoxIn(&m_sett.disp.fullFps, fpsBot))->reload();

    QCheckBox *vSyncBox = new QCheckBox("vSync");
    vSyncBox->setMaximumHeight(19);
    statusBar()->addPermanentWidget(vSyncBox);
    (new CheckBoxIn(&m_sett.disp.vSync, vSyncBox))->reload();

    QAction *confVis = new QAction("Display", view);
    view->addAction(confVis);
    m_control->connectAction(confVis);
    QAction *editVis = new QAction("Edit", view);
    view->addAction(editVis);
    m_edDlg->connectAction(editVis);

    m_kView->connectedInit();

    processCmdArgs();
}
示例#5
0
文件: converter.cpp 项目: 2php/pcl
/**
 * Parse input files and options. Calls the right conversion function.
 * @param argc[in]
 * @param argv[in]
 * @return 0 on success, any other value on failure.
 */
int
main (int argc,
      char** argv)
{
  // Display help
  if (pcl::console::find_switch (argc, argv, "-h") != 0 || pcl::console::find_switch (argc, argv, "--help") != 0)
  {
    displayHelp (argc, argv);
    return (0);
  }

  // Parse all files and options
  std::vector<std::string> supported_extensions;
  supported_extensions.push_back("obj");
  supported_extensions.push_back("pcd");
  supported_extensions.push_back("ply");
  supported_extensions.push_back("stl");
  supported_extensions.push_back("vtk");
  std::vector<int> file_args;
  for (int i = 1; i < argc; ++i)
    for (size_t j = 0; j < supported_extensions.size(); ++j)
      if (boost::algorithm::ends_with(argv[i], supported_extensions[j]))
      {
        file_args.push_back(i);
        break;
      }

  std::string parsed_output_type;
  pcl::console::parse_argument (argc, argv, "-f", parsed_output_type);
  pcl::console::parse_argument (argc, argv, "--format", parsed_output_type);
  bool cloud_output (false);
  if (pcl::console::find_switch (argc, argv, "-c") != 0 ||
      pcl::console::find_switch (argc, argv, "--cloud") != 0)
    cloud_output = true;

  // Make sure that we have one input and one output file only
  if (file_args.size() != 2)
  {
    PCL_ERROR ("Wrong input/output file count!\n");
    displayHelp (argc, argv);
    return (-1);
  }

  // Convert parsed output type to output type
  int output_type (BINARY);
  if (!parsed_output_type.empty ())
  {
    if (parsed_output_type == "ascii")
      output_type = ASCII;
    else if (parsed_output_type == "binary")
      output_type = BINARY;
    else if (parsed_output_type == "binary_compressed")
      output_type = BINARY_COMPRESSED;
    else
    {
      PCL_ERROR ("Wrong output type!\n");
      displayHelp (argc, argv);
      return (-1);
    }
  }

  // Try to load as mesh
  pcl::PolygonMesh mesh;
  if (boost::filesystem::path (argv[file_args[0]]).extension () != ".pcd" &&
      pcl::io::loadPolygonFile (argv[file_args[0]], mesh) != 0)
  {
    PCL_INFO ("Loaded a mesh with %d points (total size is %d) and the following channels:\n%s\n",
             mesh.cloud.width * mesh.cloud.height, mesh.cloud.data.size (), pcl::getFieldsList (mesh.cloud).c_str ());

    if (cloud_output)
      mesh.polygons.clear();

    if (saveMesh (mesh, argv[file_args[1]], output_type))
      return (-1);
  }
  else if (boost::filesystem::path (argv[file_args[0]]).extension () == ".stl")
  {
    PCL_ERROR ("Unable to load %s.\n", argv[file_args[0]]);
    return (-1);
  }
  else
  {
    // PCD, OBJ, PLY or VTK
    if (boost::filesystem::path (argv[file_args[0]]).extension () != ".pcd")
      PCL_WARN ("Could not load %s as a mesh, trying as a point cloud instead.\n", argv[file_args[0]]);

    //Eigen::Vector4f origin; // TODO: Support origin/orientation
    //Eigen::Quaternionf orientation;
    pcl::PCLPointCloud2::Ptr cloud (new pcl::PCLPointCloud2);
    if (pcl::io::load (argv[file_args[0]], *cloud) < 0)
    {
      PCL_ERROR ("Unable to load %s.\n", argv[file_args[0]]);
      return (-1);
    }

    PCL_INFO ("Loaded a point cloud with %d points (total size is %d) and the following channels:\n%s\n", cloud->width * cloud->height, cloud->data.size (),
              pcl::getFieldsList (*cloud).c_str ());

    if (!savePointCloud (cloud, argv[file_args[1]], output_type))
    {
      PCL_ERROR ("Failed to save %s.\n", argv[file_args[1]]);
      return (-1);
    }
  }
  return (0);
}
示例#6
0
int __cdecl buildMeshFromFile(int userId, const char* inputFilename, const char* navmeshFilename, BuildMeshCallback callback, int numCores) 
{
	WCellBuildContext ctx;
	dtNavMesh* mesh = NULL;

	if (navmeshFilename) {
		// load navmesh from file
		mesh = loadMesh(navmeshFilename);
	}
	
	if (!mesh) { 
		InputGeom geom;
		dtNavMeshQuery* navMeshQuery;

		// no navmesh has been loaded
		// Load input mesh
		if (!geom.loadMesh(&ctx, inputFilename)) {
			return 0;
		}

		// build nav-mesh
		mesh = buildMesh(&geom, &ctx, numCores);
		if (!mesh) {
			// building failed
			return 0;
		}

		if (navmeshFilename) {
			// save to file
			saveMesh(navmeshFilename, mesh);
		}
	}

	//int tileCount = 0;
	int vertCount = 0;
	int polyCount = 0;
	int totalPolyVertCount = 0;

	float* allVerts;
	unsigned char* polyVertCounts;
	unsigned int* polyVerts;
	unsigned int* polyNeighbors;
	unsigned short* polyFlags;
	unsigned char* polyAreasAndTypes;

	// count sizes and offsets
	unsigned int* tilePolyIndexOffsets = new unsigned int[mesh->getMaxTiles()];

	int maxTiles = mesh->getMaxTiles();
	//int maxTiles = 1;
	for (int i = 0; i < maxTiles; ++i)
	{
		const dtMeshTile* tile = ((const dtNavMesh*)mesh)->getTile(i);
		if (!tile || !tile->header || !tile->dataSize) continue;

		//tileCount++;
		tilePolyIndexOffsets[i] = polyCount;

		polyCount += tile->header->polyCount;
		vertCount += tile->header->vertCount;

		for (int j = 0; j < tile->header->polyCount; j++) {
			totalPolyVertCount += tile->polys[j].vertCount;
		}
	}

	// allocate arrays
	allVerts = new float[vertCount * 3];
	polyVertCounts = new unsigned char[polyCount];
	polyVerts = new unsigned int[totalPolyVertCount];
	polyNeighbors = new unsigned int[totalPolyVertCount];
	polyFlags = new unsigned short[polyCount];
	polyAreasAndTypes = new unsigned char[polyCount];

	int p = 0;
	int v = 0;
	int polyIndexOffset = 0;


	// copy data
	// iterate tiles
	for (int i = 0; i < maxTiles; ++i)
	{
		const dtMeshTile* tile = ((const dtNavMesh*)mesh)->getTile(i);
		if (!tile || !tile->header || !tile->dataSize) continue;

		memcpy(&allVerts[v], tile->verts, tile->header->vertCount * sizeof(float) * 3);

		int vc = v/3;

		// iterate polygons
		for (int j = 0; j < tile->header->polyCount; j++) {
			int absolutePolyIndex = p+j;
			dtPoly& poly = tile->polys[j];

			polyVertCounts[absolutePolyIndex] = poly.vertCount;

			// iterate polygon vertices and edges
			for (int k = 0; k < poly.vertCount; k++) {
				int absolutePolyVertIndex = polyIndexOffset + k;

				polyVerts[absolutePolyVertIndex] = vc + poly.verts[k];

				// find absolute index of neighbor poly
				unsigned short neiRef = poly.neis[k];
				unsigned int idx = (unsigned int)-1;
				if (neiRef & DT_EXT_LINK)
				{
					// Tile border edge -> find linked polygon
					for (unsigned int l = poly.firstLink; l != DT_NULL_LINK; l = tile->links[l].next)
					{
						const dtLink* link = &tile->links[l];
						if (link->ref != 0 && link->edge == k)
						{
							// lookup linked neighbor tile and poly
							unsigned int salt, neigTile, neiPoly;
							mesh->decodePolyId(link->ref, salt, neigTile, neiPoly);

							// absolute poly index
							idx = tilePolyIndexOffsets[neigTile] + neiPoly;

							//const dtMeshTile* t = ((const dtNavMesh*)mesh)->getTile(neigTile);
							assert(neigTile < maxTiles-1 || idx < tilePolyIndexOffsets[neigTile+1]);
							//idx = (unsigned int)-1;
						}
					}
				}
				else if (neiRef)
				{
					// Tile-internal edge
					idx = tilePolyIndexOffsets[i] + (unsigned int)(neiRef - 1);
				}

				assert((int)idx == -1 || idx < polyCount);

				polyNeighbors[absolutePolyVertIndex] = idx;
			}
			polyIndexOffset += poly.vertCount;
		}

		v += tile->header->vertCount * 3;
		p += tile->header->polyCount;
	}
	
	assert(v/3 == vertCount);

	printf("Preparing navmesh with %d vertices...\n", vertCount);

	callback(
		userId, 
		vertCount * 3, 
		polyCount,
		allVerts, 
		totalPolyVertCount, 
		polyVertCounts, 
		polyVerts, 
		polyNeighbors, 
		polyFlags,
		polyAreasAndTypes
		);
	
	delete[] allVerts;
	delete[] polyVertCounts;
	delete[] polyVerts;
	delete[] polyNeighbors;
	delete[] polyFlags;
	delete[] polyAreasAndTypes;
	delete[] tilePolyIndexOffsets;
	CleanupAfterBuild();

	return 1;
}
示例#7
0
void ISCExport::saveISC(const TCHAR *name,ExpInterface *ei,Interface *i)
{
	SceneEnumerator enumerator(ei,i);

	// No triobjects to export -> quit
	if (enumerator.numTriobjects()==0) return;

	size_t objnum=0;
	unsigned long chunksize,namessize=0;

	FILE *outfile=fopen(name,"wb");
	if (!outfile) return;

	for (objnum=0;objnum<enumerator.numTriobjects();++objnum)
		namessize+=(unsigned long)(enumerator.triobjectname(objnum).length())+1;


	fwrite("isc0",1,4,outfile);


	fwrite("objt",1,4,outfile);
	chunksize=(unsigned long)(enumerator.numTriobjects()*(3*sizeof(float)+4*sizeof(float)+4))+namessize;
	fwrite(&chunksize,1,4,outfile);
	{ DWORD numobjs=(DWORD)(enumerator.numTriobjects()); fwrite(&numobjs,1,4,outfile); }

	for (objnum=0;objnum<enumerator.numTriobjects();++objnum) {
		TriObject *pTriobj=enumerator.triobject(objnum);
		std::string objname=enumerator.triobjectname(objnum);
		Matrix3 *pTM=enumerator.triobjecttransform(objnum);

		/*Point3 trans=pTM->GetTrans();
		Quat rot(*pTM);*/
		AffineParts parts;
		decomp_affine(*pTM,&parts);
		Point3 trans=parts.t;
		Quat rot=parts.q;

		//float ang[3];
		//QuatToEuler(rot,ang);
		/*rot.GetEuler(&ang[0],&ang[1],&ang[2]);
		//{ float f=ang[1]; ang[1]=ang[2]; ang[2]=f; }
		rot.SetEuler(ang[0],ang[2],ang[1]);*/

		trans.x=trans.y=trans.z=0;
		rot.Identity();

		fwrite(objname.c_str(),1,objname.length()+1,outfile);

		//trans.x*=-1;

		fwrite(&(trans.x),1,sizeof(float),outfile);
		fwrite(&(trans.y),1,sizeof(float),outfile);
		fwrite(&(trans.z),1,sizeof(float),outfile);

		fwrite(&(rot.x),1,sizeof(float),outfile);
		fwrite(&(rot.y),1,sizeof(float),outfile);
		fwrite(&(rot.z),1,sizeof(float),outfile);
		fwrite(&(rot.w),1,sizeof(float),outfile);

		fwrite(&objnum,1,4,outfile);
	}


	fwrite("mesh",1,4,outfile);
	chunksize=(unsigned long)(enumerator.numTriobjects()*(2*4 + 3*4 + 4 + (3+3+2+3+3)*sizeof(float)))+namessize;
	fwrite(&chunksize,1,4,outfile);
	{ DWORD numobjs=(DWORD)(enumerator.numTriobjects()); fwrite(&numobjs,1,4,outfile); }

	for (objnum=0;objnum<enumerator.numTriobjects();++objnum) {
		Matrix3 *pTM=enumerator.triobjecttransform(objnum);

		TriObject *pTriobj=enumerator.triobject(objnum);
		std::string objname=enumerator.triobjectname(objnum);
		fwrite(objname.c_str(),1,objname.length()+1,outfile);
		saveMesh(outfile,pTriobj,pTM,enumerator.triobjectmaterial(objnum),enumerator);
	}


	fwrite("mtrl",1,4,outfile);
	chunksize=0;
	fwrite(&chunksize,1,4,outfile);
	{ DWORD nummtrls=(DWORD)(enumerator.numMaterials()); fwrite(&nummtrls,1,4,outfile); }

	for (size_t mtrlnum=0;mtrlnum<enumerator.numMaterials();++mtrlnum) {
		Mtl* pMtl=enumerator.material(mtrlnum);
		saveMaterial(outfile,pMtl);
	}


	fclose(outfile);
}