Exemple #1
0
void
vpSimulator::save(const char *name,bool binary)
{
  // get a pointer to the object "name"
  SoOutput output ;
  output.openFile(name) ;

  if (binary==true)  output.setBinary(TRUE) ;

  SoWriteAction writeAction(&output) ;
  writeAction.apply(scene) ;
  output.closeFile() ;

}
void
SoIntersectionDetectionAction::apply(SoNode * node)
{
  // Keep this around, as it's handy for dumping a stand-alone scene
  // to work with from an invocation within an application framework.
#if 0 // disabled
  SoOutput out;
  SbBool ok = out.openFile("/tmp/assembly.wrl");
  assert(ok);
  SoWriteAction wa(&out);
  wa.apply(node);
  out.closeFile();
#endif // disabled

  PRIVATE(this)->reset();

  // Needs a bounding box for the full scene, for later initialization
  // of the SbOctTree of shape bounding boxes.
  SbViewportRegion vp;
  SoGetBoundingBoxAction bboxaction(vp);
  bboxaction.apply(node);
  PRIVATE(this)->fullxfbbox = bboxaction.getXfBoundingBox();

  if (ida_debug()) { // debug
    SoGetPrimitiveCountAction counter;
    counter.apply(node);
    SoDebugError::postInfo("SoIntersectionDetectionAction::apply",
                           "number of triangle primitives in scene: %d",
                           counter.getTriangleCount());
  }

  PRIVATE(this)->traverser->apply(node);

  SbTime starttime;
  if (ida_debug()) { // debug
    starttime = SbTime::getTimeOfDay();
    SoDebugError::postInfo("SoIntersectionDetectionAction::apply",
                           "calling doIntersectionTesting()...");
  }

  PRIVATE(this)->doIntersectionTesting();

  if (ida_debug()) { // debug
    SoDebugError::postInfo("SoIntersectionDetectionAction::apply",
                           "doIntersectionTesting() done after %f seconds.",
                           (SbTime::getTimeOfDay() - starttime).getValue());
  }
}
Exemple #3
0
void
MainWindow::saveScene()
{
	SoOutput output;
	
	if (!output.openFile(QString("coach-" + QDateTime::currentDateTime().toString("yyyyMMdd-HHmmsszzz") + ".wrl").toStdString().c_str()))
	{
		return;
	}
	
	output.setHeaderString("#VRML V2.0 utf8");
	
	SoWriteAction writeAction(&output);
	writeAction.apply(this->scene->root);
	
	output.closeFile();
}
Exemple #4
0
void
Viewer::saveScene()
{
	QString filename = "rlPlanDemo-" + QDateTime::currentDateTime().toString("yyyyMMdd-HHmmsszzz") + ".wrl";
	
	SoOutput output;
	
	if (!output.openFile(filename.toStdString().c_str()))
	{
		return;
	}
	
	output.setHeaderString("#VRML V2.0 utf8");
	
	SoWriteAction writeAction(&output);
	writeAction.apply(this->root);
	
	output.closeFile();
	
	MainWindow::instance()->statusBar()->showMessage("Successfully saved scene in '" + filename + "'.", 1000);
}
bool CoinVisualizationNode::saveModel(const std::string &modelPath, const std::string &filename)
{
	std::string outFile = filename;

	boost::filesystem::path completePath(modelPath);
	boost::filesystem::path fn(outFile);

	if (!boost::filesystem::is_directory(completePath))
	{
		if (!boost::filesystem::create_directories(completePath))
		{
			VR_ERROR << "Could not create model dir  " << completePath.string() << endl;
			return false;
		}
	}

	boost::filesystem::path completeFile = boost::filesystem::operator/(completePath,fn);

    SoOutput* so = new SoOutput();
    if (!so->openFile(completeFile.string().c_str()))
    {
        VR_ERROR << "Could not open file " << completeFile.string() << " for writing." << endl;
    }
	SoGroup *n = new SoGroup;
	n->ref();
	n->addChild(visualization);
	SoGroup* newVisu = CoinVisualizationFactory::convertSoFileChildren(n);
	newVisu->ref();
    SoWriteAction wa(so);
    wa.apply(newVisu);
	so->closeFile();

	newVisu->unref();
	n->unref();

    return true;
}
Exemple #6
0
int
main(int argc, char ** argv)
{
  fprintf(stderr, "ivcp v0.1\n");

  SoDB::init();
  SoNodeKit::init();
  SoInteraction::init();

  if (argc != 3 ) {
    fprintf(stdout, "Usage: %s infile outfile\n", argv[0]);
    return 0;
  }

  SoInput * in = new SoInput;
  if (!in->openFile(argv[1])) {
    fprintf(stderr, "error: could not open file '%s'\n", argv[1]);
    delete in;
    SoDB::cleanup();
    return -1;
  }

  SoNode * scene = SoDB::readAll(in);

  if (!scene) {
    fprintf(stderr, "error: could not read file '%s'\n", argv[1]);
    delete in;
    SoDB::cleanup();
    return -1;
  }
  FileType inputFileType;
  if (in->isFileVRML1())
    inputFileType = VRML1;
  else if (in->isFileVRML2())
    inputFileType = VRML2;
  else
    inputFileType = INVENTOR;

  delete in;
  scene->ref();

  SoNode * firstChild = static_cast<SoSeparator*>(scene)->getNumChildren()?
    static_cast<SoSeparator*>(scene)->getChild(0)
    :NULL;

  if (firstChild && firstChild->isOfType(SoForeignFileKit::getClassTypeId())) {
    SoForeignFileKit * kit = (SoForeignFileKit *) firstChild;
    if (kit->canWriteScene() ) {
      SoNode * subscene = NULL;
      kit->writeScene(subscene);
      if (!subscene ) {
        return -1;
      }
      subscene->ref();
      scene->unref();
      scene = subscene;
    }
  }

  SoOutput * out = new SoOutput;
  if (!out->openFile(argv[2])) {
    fprintf(stderr, "error: could not open file '%s' for writing\n");
    scene->unref();
    delete out;
    SoDB::cleanup();
    return -1;
  }
  switch (inputFileType) {
  case VRML1:
    out->setHeaderString("#VRML V1.0 ascii");
    break;
  case VRML2:
    out->setHeaderString("#VRML V2.0 utf8");
  }

  SoWriteAction wa(out);
  wa.apply(scene);

  out->closeFile();
  delete out;

  scene->unref();

  // with actions on the stack, cleanup can't be called...
  // SoDB::cleanup();
  return 0;
}
Exemple #7
0
int
main(int argc, char** argv)
{
	if (argc != 3)
	{
		std::cerr << "Usage: tris2wrl [input.tris] [output.wrl]" << std::endl;
		return EXIT_FAILURE;
	}
	
	SoDB::init();
	
	std::fstream file;
	file.open(argv[1]);
	
	std::string line;
	std::vector<std::string> tokens;
	
	std::getline(file, line);
	
	if (!boost::starts_with(line, "#"))
	{
		file.close();
		return EXIT_FAILURE;
	}
	
	SoVRMLTransform* root = new SoVRMLTransform();
	root->ref();
	
	SoVRMLShape* shape = new SoVRMLShape();
	root->addChild(shape);
	
	SoVRMLAppearance* appearance = new SoVRMLAppearance();
	shape->appearance = appearance;
	
	SoVRMLMaterial* material = new SoVRMLMaterial();
	appearance->material = material;
	
	SoVRMLIndexedFaceSet* indexedFaceSet = new SoVRMLIndexedFaceSet();
	shape->geometry = indexedFaceSet;
	
	SoVRMLCoordinate* coordinate = new SoVRMLCoordinate();
	indexedFaceSet->coord = coordinate;
	
	SoVRMLColor* color = new SoVRMLColor();
	indexedFaceSet->color = color;
	
	indexedFaceSet->colorPerVertex.setValue(false);
	indexedFaceSet->solid.setValue(false);
	
	while (-1 != file.peek())
	{
		std::getline(file, line);
		
		if (line.empty())
		{
			continue;
		}
		else if (boost::starts_with(line, "#"))
		{
			break;
		}
		
		boost::trim(line);
		boost::split(tokens, line, boost::is_space(), boost::token_compress_on);
		
		coordinate->point.set1Value(coordinate->point.getNum(), std::stof(tokens[0]), std::stof(tokens[1]), std::stof(tokens[2]));
	}
	
	while (-1 != file.peek())
	{
		std::getline(file, line);
		
		if (line.empty())
		{
			continue;
		}
		else if (boost::starts_with(line, "#"))
		{
			break;
		}
		
		boost::trim(line);
		boost::split(tokens, line, boost::is_space(), boost::token_compress_on);
		
		for (std::size_t i = 0; i < tokens.size(); ++i)
		{
			indexedFaceSet->coordIndex.set1Value(indexedFaceSet->coordIndex.getNum(), std::stoi(tokens[i]));
		}
		
		indexedFaceSet->coordIndex.set1Value(indexedFaceSet->coordIndex.getNum(), -1);
	}
	
	while (-1 != file.peek())
	{
		std::getline(file, line);
		
		if (line.empty())
		{
			continue;
		}
		else if (boost::starts_with(line, "#"))
		{
			break;
		}
		
		boost::trim(line);
		boost::split(tokens, line, boost::is_space(), boost::token_compress_on);
		
		if (tokens.size() > 5)
		{
			color->color.set1Value(color->color.getNum(), std::stof(tokens[3]), std::stof(tokens[4]), std::stof(tokens[5]));
		}
	}
	
	while (-1 != file.peek())
	{
		std::getline(file, line);
		
		if (line.empty())
		{
			continue;
		}
		else if (boost::starts_with(line, "#"))
		{
			break;
		}
		
		boost::trim_if(line, boost::is_any_of(", \t\n\v\f\r"));
		boost::split(tokens, line, boost::is_any_of(", "), boost::token_compress_on);
		
		for (std::size_t i = 0; i < tokens.size(); ++i)
		{
			indexedFaceSet->colorIndex.set1Value(indexedFaceSet->colorIndex.getNum(), std::stoi(tokens[i]));
		}
	}
	
	std::cout << "coordinates: " << coordinate->point.getNum() << std::endl;
	std::cout << "faces: " << indexedFaceSet->coordIndex.getNum() / 4 << std::endl;
	std::cout << "materials: " << color->color.getNum() << std::endl;
	std::cout << "material indices: " << indexedFaceSet->colorIndex.getNum() << std::endl;
	
	if (0 == indexedFaceSet->colorIndex.getNum())
	{
		color->ref();
		indexedFaceSet->color.setValue(nullptr);
		color->unref();
	}
	
	file.close();
	
	SoOutput out;
	out.openFile(argv[2]);
	out.setHeaderString("#VRML V2.0 utf8");
	SoWriteAction wra(&out);
	wra.apply(root);
	out.closeFile();
	
	root->unref();
	
	return EXIT_SUCCESS;
}