Exemplo n.º 1
0
//Run a mesher command
int TriangleMesher::RunMesherCommand(MesherCommand* mc) {
	int ret = false;

	//Figure out which command to execute and run it
	if(mc->command_type == MesherCommand::GENERATE_RANDOM_GRID)
		ret = GenerateRandomGrid(mc->xmin, mc->xmax, mc->ymin, mc->ymax, mc->vertex_count);

	else if(mc->command_type == MesherCommand::GENERATE_UNIFORM_GRID)
		ret = GenerateUniformGrid(mc->xmin, mc->xmax, mc->ymin, mc->ymax, mc->xcount, mc->ycount);

	else if(mc->command_type == MesherCommand::GENERATE_HEX_GRID)
		ret = GenerateHexGrid(mc->xmin, mc->xmax, mc->ymin, mc->ymax, mc->xcount, mc->ycount);

	else if(mc->command_type == MesherCommand::RUN_TRIANGLE_MESHER)
		ret = RunTriangleMesher(mc->use_kd_tree);

	else if(mc->command_type == MesherCommand::LOAD_MESH_FROM_FILE)
		ret = LoadMeshFromFile(mc->filename, mc->load_save_triangles);

	else if(mc->command_type == MesherCommand::SAVE_MESH_TO_FILE)
		ret = SaveMeshToFile(mc->filename, mc->load_save_triangles);

	else if(mc->command_type == MesherCommand::WRITE_SVG)
		ret = WriteSVG(mc->svg_filename, mc->svg_width, mc->svg_height);

	else if(mc->command_type == MesherCommand::SUBDIVIDE_TRIANGLE)
		ret = SubdivideTriangle(mc->subdivide_vindex, mc->subdivide_triangle_local_index);

	else if(mc->command_type == MesherCommand::BARYCENTRIC_SUBDIVIDE)
		ret = BarycentricSubdivide(mc->subdivide_triangle_local_index);

	else if(mc->command_type == MesherCommand::BASIC_TRIANGLE_MESHER)
		ret = BasicTriangleMesher();

	else if(mc->command_type == MesherCommand::STRETCHED_GRID)
		ret = StretchedGrid(mc->stretched_grid_iterations, mc->stretched_grid_alpha);

	else if(mc->command_type == MesherCommand::REFINE_MESH)
		ret = RefineMesh(mc->desired_edge_length);

	else if(mc->command_type == MesherCommand::DO_NOTHING)
		ret = true;


	//Update the mesher command result
	if(ret == false) {
		mc->mesher_command_result = MesherCommand::FAILURE_RESULT;
		return false;
	}

	else {
		mc->mesher_command_result = MesherCommand::SUCCESS_RESULT;
		return true;
	}

	return true;
}
Exemplo n.º 2
0
bool SVGFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
  OBMol* pmol = dynamic_cast<OBMol*>(pOb);
  if(!pmol)
    return false;
  _objects.clear();
  _nmax =_nrows = _ncols = 1;
  _objects.push_back(pOb);
  bool ret = WriteSVG(pConv,_objects);
  delete _objects.front();
  _objects.clear();
  return true;
}
Exemplo n.º 3
0
bool SVGFormat::WriteChemObject(OBConversion* pConv)
{
  //Molecules are stored here as pointers to OBBase objects, which are not deleted as usual.
  //When there are no more they are sent to WriteMolecule.
  //This allows their number to be determined whatever their source
  //(they may also have been filtered), so that the table can be properly dimensioned.

  //NOT CURRENTLY IMPLEMENTED
  //If the first object is OBText, the part of it before each insertion point (if it exists)
  //is output before every molecule. This allows molecule structures to be displayed
  //in a template. The x option to omit the XML header is set

  OBBase* pOb = pConv->GetChemObject();

  if(pConv->GetOutputIndex()<=1)
  {
    _objects.clear();
    _nmax=0;

    pConv->AddOption("svgbswritechemobject"); // to show WriteMolecule that this function has been called
    const char* pc = pConv->IsOption("c");
    //alternative for babel because -xc cannot take a parameter, because some other format uses it
    //similarly for -xr -xp
    if(!pc)
      pc = pConv->IsOption("cols", OBConversion::GENOPTIONS);
    const char* pr = pConv->IsOption("r");
    if(!pr)
      pr = pConv->IsOption("rows", OBConversion::GENOPTIONS);
    if(pr)
      _nrows = atoi(pr);
    if(pc)
      _ncols = atoi(pc);
    if(pr && pc) // both specified: fixes maximum number objects to be output
      _nmax = _nrows * _ncols;

    //explicit max number of objects
    const char* pmax =pConv->IsOption("N");
    if(pmax)
      _nmax = atoi(pmax);
  }

  OBMoleculeFormat::DoOutputOptions(pOb, pConv);

  //save molecule
  _objects.push_back(pOb);

  bool ret=true;
  //Finish if no more input or if the number of molecules has reached the allowed maximum(if specified)
  bool nomore = _nmax && (_objects.size()==_nmax);
  if((pConv->IsLast() || nomore))
  {
    int nmols = _objects.size();
    //Set table properties according to the options and the number of molecules to be output
    if (!(nmols==0 ||                      //ignore this block if there is no input or
         (_nrows && _ncols) ||             //if the user has specified both rows and columns or
         (!_nrows && !_ncols && nmols==1)))//if neither is specified and there is one output molecule
    {
      if(!_nrows && !_ncols ) //neither specified
      {
        //assign cols/rows in square
        _ncols = (int)ceil(sqrt(((double)nmols)));
      }

      if(_nrows)
        _ncols = (nmols-1) / _nrows + 1; //rounds up
      else if(_ncols)
        _nrows = (nmols-1) / _ncols + 1;
    }

    //output all collected molecules
    unsigned int n=0;

    ret = WriteSVG(pConv, _objects);

    //delete all the molecules
    vector<OBBase*>::iterator iter;
    for(iter=_objects.begin();iter!=_objects.end(); ++iter)
      delete *iter;
    delete _ptext;//delete text, NULL or not

    _objects.clear();
    _ptext = NULL;
    _nmax = _ncols = _nrows = 0;
  }
  return ret && !nomore;
}