Exemplo n.º 1
0
void testD()
{
	printf("==== Test D ====\n");
	Body b1 = loadBody("modelOne", "defaultSolver", "cubicMesh");
	Body b2 = loadBody("modelThree", "customSolver", "myCustomTetrMesh");
	b1.doCalc();
	b2.doCalc();
	printf("\n");
}
Exemplo n.º 2
0
void testC()
{
	printf("==== Test C ====\n");
	Body b = loadBody("modelThree", "customSolver", "myCustomTetrMesh");
	b.doCalc();
	printf("\n");
}
Exemplo n.º 3
0
void testB()
{
	printf("==== Test B ====\n");
	Body b = loadBody("modelTwo", "defaultSolver", "cubicMesh");
	b.doCalc();
	printf("\n");
}
Exemplo n.º 4
0
void testA()
{
	printf("==== Test A ====\n");
	Body b = loadBody("modelOne", "defaultSolver", "tetrMesh");
	b.doCalc();
	printf("\n");
}
Exemplo n.º 5
0
void Creature::loadAppearance() {
	PartModels parts;

	getPartModels(parts);

	if ((parts.type == "P") || parts.body.empty()) {
		warning("TODO: Model \"%s\": ModelType \"%s\" (\"%s\")",
		        _tag.c_str(), parts.type.c_str(), parts.body.c_str());
		return;
	}

	loadBody(parts);
	loadHead(parts);
}
Exemplo n.º 6
0
//------------------------------------------------------------------------------
Particles LoadParticles::load(string loadPath, string format, bool bin,
                              unordered_map<string, int> loadParameters) {
  m_format = format;
  m_binary = bin;
  Particles particles;

  if (m_binary) {
    FILE *binaryData = fopen(loadPath.c_str(), "rb");

    if (!binaryData) {
      cerr << "ERROR: Could not open " << loadPath << endl;
    }

    if (m_format == "xyz") {
      cerr << "Binary xyz not implemented" << endl;
      throw 10;
    } else if (m_format == "ply") {
      loadParameters = read_plyBinaryHeader(binaryData, loadParameters);
    } else if (m_format == "lmp") {
      read_lmpBinaryHeader(binaryData, loadParameters);
    } else {
      cerr << "Format: '" << m_format << "' not supported" << endl;
      throw 10;
    }

    loadBinaryBody(particles, binaryData, loadParameters);
    fclose(binaryData);
  } else {
    std::fstream data(loadPath, std::ios::in);
    unordered_map<std::string, int> parameters;

    if (m_format == "xyz") {
      parameters = read_xyzHeader(data);
    } else if (m_format == "ply") {
      cerr << "ply not implemented" << endl;
      throw 10;
    } else if (m_format == "lmp") {
      parameters = read_lmpHeader(data);
    } else {
      cerr << "Format: '" << m_format << "' not supported" << endl;
      throw 10;
    }

    loadBody(particles, data, parameters);
    data.close();
  }

  return particles;
}
Exemplo n.º 7
0
void CCharacter::loadAttributes(CXMLParser::TXML *data){
	// leo las caracteristicas del player
	for(vu8 i = 0; i < data->numChilds; ++i){
		if(strcmp(data->childs[i]->tag, "health") == 0){
			_health = atoi(data->childs[i]->value);
		}else if(strcmp(data->childs[i]->tag, "maxJumpHeight") == 0){
			_maxJumpHeight = _position->getY() - atoi(data->childs[i]->value);
			printf("\n\n%d",_maxJumpHeight );
		}else if(strcmp(data->childs[i]->tag, "body") == 0){
			loadBody(data->childs[i]);
		}

	}

	_horizontalSpeed = new Vector2(2,0);
} // loadAttributes
Exemplo n.º 8
0
void Creature::loadEquippedModel() {
	uint32 state;
	uint8 textureVariation;
	getModelState(state, textureVariation);

	PartModels parts;
	if (_isPC) {
		getPartModelsPC(parts, state, textureVariation);
		_portrait = parts.portrait;
	} else {
		getPartModels(parts, state, textureVariation);
		if ((_modelType == "P") || parts.body.empty()) {
			warning("TODO: Model \"%s\": ModelType \"%s\" (\"%s\")",
			        _tag.c_str(), _modelType.c_str(), parts.body.c_str());

			return;
		}
	}

	loadBody(parts);
	loadHead(parts);

	if (!_model)
		return;

	attachWeaponModel(kInventorySlotLeftWeapon);
	attachWeaponModel(kInventorySlotRightWeapon);

	setDefaultAnimations();

	if (_visible) {
		float x, y, z;
		getPosition(x, y, z);
		_model->setPosition(x, y, z);

		float angle;
		getOrientation(x, y, z, angle);
		_model->setOrientation(x, y, z, angle);

		_model->show();
	}
}
Exemplo n.º 9
0
void KoTextLoader::loadBody(const KoXmlElement &bodyElem, QTextCursor &cursor)
{
    const QTextBlockFormat defaultBlockFormat = cursor.blockFormat();
    const QTextCharFormat defaultCharFormat = cursor.charFormat();

    const QTextDocument *document = cursor.block().document();
    d->styleManager = KoTextDocument(document).styleManager();
    Q_ASSERT(d->styleManager);

    d->changeTracker = KoTextDocument(document).changeTracker();
//    if (!d->changeTracker)
//        d->changeTracker = dynamic_cast<KoChangeTracker *>(d->context.dataCenterMap().value("ChangeTracker"));
//    Q_ASSERT(d->changeTracker);

    kDebug(32500) << "text-style:" << KoTextDebug::textAttributes( cursor.blockCharFormat() );
#if 0
    if ((document->isEmpty()) && (d->styleManager)) {
        QTextBlock block = cursor.block();
        d->styleManager->defaultParagraphStyle()->applyStyle(block);
    }
#endif

    startBody(KoXml::childNodesCount(bodyElem));
    KoXmlElement tag;
    bool usedParagraph = false; // set to true if we found a tag that used the paragraph, indicating that the next round needs to start a new one.
    forEachElement(tag, bodyElem) {
        if (! tag.isNull()) {
            const QString localName = tag.localName();
            if (tag.namespaceURI() == KoXmlNS::text) {
                if (usedParagraph)
                    cursor.insertBlock(defaultBlockFormat, defaultCharFormat);
                usedParagraph = true;
                if (d->changeTracker && localName == "tracked-changes") {
                    d->changeTracker->loadOdfChanges(tag);
                    usedParagraph = false;
                } else if (d->changeTracker && localName == "change-start") {
                    loadChangedRegion(tag, cursor);
                    usedParagraph = false;
                } else if (d->changeTracker && localName == "change-end") {
                    d->currentChangeId = 0;
                    usedParagraph = false;
                } else if (localName == "p") {    // text paragraph
                    loadParagraph(tag, cursor);
                } else if (localName == "h") {  // heading
                    loadHeading(tag, cursor);
                } else if (localName == "unordered-list" || localName == "ordered-list" // OOo-1.1
                           || localName == "list" || localName == "numbered-paragraph") {  // OASIS
                    loadList(tag, cursor);
                } else if (localName == "section") {  // Temporary support (###TODO)
                    loadSection(tag, cursor);
                } else {
                    KoVariable *var = KoVariableRegistry::instance()->createFromOdf(tag, d->context);

                    if (var) {
                        KoTextDocumentLayout *layout = dynamic_cast<KoTextDocumentLayout*>(cursor.block().document()->documentLayout());
                        if (layout) {
                            KoInlineTextObjectManager *textObjectManager = layout->inlineTextObjectManager();
                            if (textObjectManager) {
                                KoVariableManager *varManager = textObjectManager->variableManager();
                                if (varManager) {
                                    textObjectManager->insertInlineObject(cursor, var);
                                }
                            }
                        }
                    } else {
                        usedParagraph = false;
                        kWarning(32500) << "unhandled text:" << localName;
                    }
                }
            } else if (tag.namespaceURI() == KoXmlNS::draw) {
                loadShape(tag, cursor);
            } else if (tag.namespaceURI() == KoXmlNS::table) {
                if (localName == "table") {
                    loadTable(tag, cursor);
                } else {
                    kWarning(32500) << "unhandled table:" << localName;
                }
#if 0 // TODO commented out for now
                if (localName == "table") {
                    cursor.insertText("\n");
                    cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);
                    QTextTable *tbl = cursor.insertTable(1, 1);
                    int rows = 0;
                    int columns = 0;
                    kDebug(32500) << "Table inserted";
                    KoXmlElement tblTag;
                    forEachElement(tblTag, tag) {
                        if (! tblTag.isNull()) {
                            const QString tblLocalName = tblTag.localName();
                            if (tblTag.namespaceURI() == KoXmlNS::table) {
                                if (tblLocalName == "table-column") {
                                    // Do some parsing with the column, see §8.2.1, ODF 1.1 spec
                                    int repeatColumn = tblTag.attributeNS(KoXmlNS::table, "number-columns-repeated", "1").toInt();
                                    columns = columns + repeatColumn;
                                    if (rows > 0)
                                        tbl->resize(rows, columns);
                                    else
                                        tbl->resize(1, columns);
                                } else if (tblLocalName == "table-row") {
                                    // Lot of work to do here...
                                    rows++;
                                    if (columns > 0)
                                        tbl->resize(rows, columns);
                                    else
                                        tbl->resize(rows, 1);
                                    // Added a row
                                    int currentCell = 0;
                                    KoXmlElement rowTag;
                                    forEachElement(rowTag, tblTag) {
                                        if (!rowTag.isNull()) {
                                            const QString rowLocalName = rowTag.localName();
                                            if (rowTag.namespaceURI() == KoXmlNS::table) {
                                                if (rowLocalName == "table-cell") {
                                                    // Ok, it's a cell...
                                                    const int currentRow = tbl->rows() - 1;
                                                    QTextTableCell cell = tbl->cellAt(currentRow, currentCell);
                                                    if (cell.isValid()) {
                                                        cursor = cell.firstCursorPosition();
                                                        loadBody(context, rowTag, cursor);
                                                    } else
                                                        kDebug(32500) << "Invalid table-cell row=" << currentRow << " column=" << currentCell;
                                                    currentCell++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    cursor = tbl->lastCursorPosition();
                    cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 1);
                } else {
                    kWarning(32500) << "KoTextLoader::loadBody unhandled table::" << localName;
                }
#endif
            }
Exemplo n.º 10
0
void Creature::loadAppearance() {
	loadBody();
	loadHead();
}
Exemplo n.º 11
0
/**
 * @brief MainWindow::MainWindow Initialize the main window and everything else
 * @param parent
 */
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
  // Initialize the interface
  ui->setupUi(this);
  ui->glWidget->addAction(ui->actionFullscreen);
  ui->glWidget->addAction(ui->actionExit);

  connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(close()));
  connect(ui->actionFullscreen,SIGNAL(triggered()),this,SLOT(toggleFullscreenSlot()));

  // The test script runs a simple experiment
  experimentScript = new TestScript(this,this);

  // Add a cosmetic line to the splitter handle
  // so that it's easier to grab with the mouse
  QSplitterHandle *handle = ui->splitter->handle(1);
  QVBoxLayout *layout = new QVBoxLayout(handle);
  layout->setSpacing(0);
  layout->setMargin(0);
  QFrame *line = new QFrame(handle);
  line->setFrameShape(QFrame::VLine);
  line->setFrameShadow(QFrame::Sunken);
  layout->addWidget(line);

  // In a future revision, we'll move the SimWorld
  // to a more intelligent place.  It doesn't
  // belong as a child to the graphics widget.
  SimWorld* world = ui->glWidget->getWorld();
  CapBody* capBody = world->getBody();
#if defined( BOARD_DATA )
  BoardMarkerData* md = ui->glWidget->getWorld()->getMarkerData();
#elif defined( POKE_DATA )
  PokeMarkerData* md = ui->glWidget->getWorld()->getMarkerData();
#else
  MarkerData* md = world->getMarkerData();
#endif

  // We populate a ScrollArea with the same number of
  // MarkerWidgets as there are markers in the data file.
  QScrollArea* sa = new QScrollArea;
  QWidget* wid = new QWidget;
  layout = new QVBoxLayout;
  layout->setContentsMargins(0,0,0,0);

  // This part needs to become part of a function
  // that is called everytime a new data file is
  // loaded.
  int markCnt = md->marker_count;
  ui->markerCountLineEdit->setText(QString::number(markCnt));
  ui->frameCountLineEdit->setText(QString::number(md->size()));
  ui->markerFileLineEdit->setText("data.c3d");
  ui->markerFrameStartBox->setValue(0);
  setDataRange(md->size());

  QHBoxLayout* innerLayout = new QHBoxLayout;
  QPushButton* connectButton = new QPushButton("Connect");
  QPushButton* releaseButton = new QPushButton("Release");
  QPushButton* updateButton = new QPushButton("Update Anchors");
  innerLayout->addWidget(connectButton);
  innerLayout->addWidget(releaseButton);
  innerLayout->addWidget(updateButton);
  connect(connectButton,SIGNAL(clicked()),this,SLOT(connectMarkers()));
  connect(releaseButton,SIGNAL(clicked()),this,SLOT(releaseMarkers()));
  connect(updateButton,SIGNAL(clicked()),this,SLOT(updateMarkerAnchors()));
  layout->addLayout(innerLayout);

  markerWidgetArray.resize(markCnt);
  for (int ii=0;ii<markCnt;++ii) {
    markerWidgetArray[ii] = new MarkerWidget(ii,0);
    layout->addWidget(markerWidgetArray[ii]);
  }
  wid->setLayout(layout);
  sa->setWidget(wid);
  ui->controlTabWidget->addTab(sa,"Markers");

  // Joint control tab
  sa = new QScrollArea;
  wid = new QWidget;
  layout = new QVBoxLayout;
  layout->setContentsMargins(0,0,0,0);

  // A couple buttons at the top of the joint tab make it possible
  // to rapidly change all the force limits
  innerLayout = new QHBoxLayout;
  QPushButton* zeroButton = new QPushButton("Zero");
  QPushButton* lightButton = new QPushButton("Light");
  QPushButton* resetButton = new QPushButton("Strong");
  innerLayout->addWidget(zeroButton);
  innerLayout->addWidget(lightButton);
  innerLayout->addWidget(resetButton);
  layout->addLayout(innerLayout);
  connect(zeroButton,SIGNAL(clicked()),this,SLOT(zeroForces()));
  connect(lightButton,SIGNAL(clicked()),this,SLOT(lightForces()));
  connect(resetButton,SIGNAL(clicked()),this,SLOT(strongForces()));

  // Fill the tab with hard-coded data about the model...
  populateJointTab(capBody,layout);
  wid->setLayout(layout);
  sa->setWidget(wid);
  ui->controlTabWidget->addTab(sa,"Joints");

  // Body dimensions widget
  sa = new QScrollArea;
  wid = new QWidget;
  layout = new QVBoxLayout;
  layout->setContentsMargins(0,0,0,0);
  QCheckBox* keepBodyRel = new QCheckBox("Body Rel");
  layout->addWidget(keepBodyRel);

  // Fill the tab with model-specific widgets
  populateBodyTab(capBody,layout);
  wid->setLayout(layout);
  sa->setWidget(wid);
  ui->controlTabWidget->addTab(sa,"Model dimensions");

  // Hook up the interface elements to their respecitve functionality
  connect(ui->saveButton,SIGNAL(clicked()),capBody,SLOT(saveBody()));
  connect(ui->loadButton,SIGNAL(clicked()),capBody,SLOT(loadBody()));
  connect(ui->testButton,SIGNAL(clicked()),this,SLOT(experimentSlot()));

  // When a the CapBody loads the marker map, tell the interface
  // how and where the markers are connected.
  connect(capBody,SIGNAL(markMap(int,int)),this,SLOT(setMarkMap(int,int)));
  connect(capBody,SIGNAL(markPoint(int,double,double,double)),
          this,SLOT(setMarkPoint(int,double,double,double)));

  // *****
  // (Each MarkerWidget informs the capBody when the interface
  //  changes).
  for (int ii=0;ii<markCnt;++ii) {
    connect(markerWidgetArray[ii],SIGNAL(markBodySet(int,int)),md,SLOT(changeBodyConnect(int,int)));
    connect(markerWidgetArray[ii],SIGNAL(markConnect(int,bool)),md,SLOT(changeBodyLink(int,bool)));
    connect(markerWidgetArray[ii],SIGNAL(markPosSet(int,double,double,double)),
            md,SLOT(changeLinkPos(int,double,double,double)));
    connect(markerWidgetArray[ii],SIGNAL(markGrab(int)),this, SLOT(grabMarkPos(int)));
  }

  connect(ui->clearPlotButton,SIGNAL(clicked()),this,SLOT(clearData()));
  connect(ui->glWidget->getWorld(),SIGNAL(useMarkers(bool)),this,SLOT(usingMarkers(bool)));
  connect(ui->frictionSpinBox,SIGNAL(valueChanged(double)),world,SLOT(setGroundFriction(double)));
  connect(ui->terrainSpinBox,SIGNAL(valueChanged(double)),world,SLOT(setTerrainSoftness(double)));
  connect(ui->zBox,SIGNAL(valueChanged(double)),ui->glWidget->getWorld(),SLOT(setTerrainZ(double)));
  connect(ui->forceLinesCheckBox,SIGNAL(clicked(bool)),ui->glWidget,SLOT(setDrawLines(bool)));
  connect(ui->camFollowCheckBox,SIGNAL(clicked(bool)),ui->glWidget,SLOT(setFollowCamera(bool)));
  connect(ui->timeSlider,SIGNAL(valueChanged(int)),world->getMarkerData(),SLOT(setFrame(int)));
  connect(ui->glWidget->getWorld()->getMarkerData(),SIGNAL(frameChanged(int)),ui->timeSlider,SLOT(setValue(int)));
  connect(ui->bodyAlpha,SIGNAL(valueChanged(double)),ui->glWidget,SLOT(setBodyAlpha(double)));
  connect(ui->showMarkBox,SIGNAL(toggled(bool)),ui->glWidget,SLOT(setShowMarkers(bool)));
  connect(ui->selfCollideBox,SIGNAL(toggled(bool)),world,SLOT(setSelfCollide(bool)));
  connect(ui->saveStateButton,SIGNAL(clicked()),this,SLOT(saveModel()));
  connect(ui->restoreButton,SIGNAL(clicked()),this,SLOT(restoreModel()));

  connect(ui->markerRadio,SIGNAL(toggled(bool)),this,SLOT(useMarkers(bool)));
  connect(ui->torqueRadio,SIGNAL(toggled(bool)),this,SLOT(useTorques(bool)));
  connect(ui->altRadio,SIGNAL(toggled(bool)),this,SLOT(useAltForces(bool)));

  connect(ui->playAllButton,SIGNAL(clicked(bool)),this,SLOT(playPauseAll(bool)));
  connect(ui->playPauseDataButton,SIGNAL(clicked(bool)),this,SLOT(playPauseData(bool)));
  connect(ui->playPauseSimButton,SIGNAL(clicked(bool)),this,SLOT(playPauseSim(bool)));

  connect(ui->stepAllButton,SIGNAL(clicked()),this,SLOT(stepAll()));
  connect(ui->stepDataButton,SIGNAL(clicked()),this,SLOT(stepData()));
  connect(ui->stepSimButton,SIGNAL(clicked()),this,SLOT(stepSim()));


  connect(ui->selectFileToolButton,SIGNAL(clicked()),this,SLOT(markerFileDialog()));
  connect(ui->dataStepBox,SIGNAL(valueChanged(int)),this,SLOT(setDataStep(int)));
  connect(ui->dataFrameBox,SIGNAL(valueChanged(int)),this,SLOT(setDataFrame(int)));
  connect(ui->timeSlider,SIGNAL(valueChanged(int)),ui->dataFrameBox,SLOT(setValue(int)));

  // *****
  // Need to dynamically change this
  ui->timeSlider->setRange(0,world->getMarkerData()->size()-1);
  connect(ui->globalBox,SIGNAL(toggled(bool)),this,SLOT(useGlobalForces(bool)));

#if defined( BOARD_DATA )
  bd = new BoardData(this);
  bd->loadData("boardData.dat");
  ui->glWidget->setBoardData(bd);
#endif

  // Start the timer for updating the data, sim, and graphics
  updateTimer.setSingleShot(false);
  connect(&updateTimer,SIGNAL(timeout()),this,SLOT(updateLoop()));

  connect(ui->frameTimeBox,SIGNAL(valueChanged(double)),this,SLOT(setFrameTime(double)));
  ui->frameTimeBox->setValue(1/60.0);
  ui->dataStepBox->setValue(2);

  capBody->loadBody();
  useMarkers(true);
  saveModel();
}
Exemplo n.º 12
0
bool CAR::LoadGraphics(
	const PTree & cfg,
	const std::string & partspath,
	const std::string & carpath,
	const std::string & carname,
	const std::string & carpaint,
	const MATHVECTOR <float, 3> & carcolor,
	const int anisotropy,
	const float camerabounce,
	const bool damage,
	const bool debugmode,
	ContentManager & content,
	std::ostream & info_output,
	std::ostream & error_output)
{
	//write_inf(cfg, std::cerr);
	cartype = carname;
	LoadDrawable loadDrawable(carpath, anisotropy, content, models, error_output);

	// load body first
	const PTree * cfg_body;
	std::string meshname;
	std::vector<std::string> texname;
	if (!cfg.get("body", cfg_body, error_output))
	{
		error_output << "there is a problem with the .car file" << std::endl;
		return false;
	}
	if (!cfg_body->get("mesh", meshname, error_output)) return false;
	if (!cfg_body->get("texture", texname, error_output)) return false;
	if (carpaint != "default") texname[0] = carpaint;
	if (!loadDrawable(meshname, texname, *cfg_body, topnode, &bodynode)) return false;

	// load wheels
	const PTree * cfg_wheel;
	if (!cfg.get("wheel", cfg_wheel, error_output)) return false;
	for (PTree::const_iterator i = cfg_wheel->begin(); i != cfg_wheel->end(); ++i)
	{
		if (!LoadWheel(i->second, loadDrawable, topnode, error_output))
		{
			error_output << "Failed to load wheels." << std::endl;
			return false;
		}
	}

	// load drawables
	LoadBody loadBody(topnode, bodynode, loadDrawable);
	for (PTree::const_iterator i = cfg.begin(); i != cfg.end(); ++i)
	{
		if (i->first != "body" &&
			i->first != "steering" &&
			i->first != "light-brake" &&
			i->first != "light-reverse")
		{
			loadBody(i->second);
		}
	}

	// load steering wheel
	const PTree * cfg_steer;
	if (cfg.get("steering", cfg_steer))
	{
		SCENENODE & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_steer, bodynoderef, &steernode, 0))
		{
			error_output << "Failed to load steering wheel." << std::endl;
			return false;
		}
		cfg_steer->get("max-angle", steer_angle_max);
		steer_angle_max = steer_angle_max / 180.0 * M_PI;
		SCENENODE & steernoderef = bodynoderef.GetNode(steernode);
		steer_orientation = steernoderef.GetTransform().GetRotation();
	}

	// load brake/reverse light point light sources (optional)
	int i = 0;
	std::string istr = "0";
	const PTree * cfg_light;
	while (cfg.get("light-brake-"+istr, cfg_light))
	{
		if (!LoadLight(*cfg_light, content, error_output))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}

		std::stringstream sstr;
		sstr << ++i;
		istr = sstr.str();
	}
	i = 0;
	istr = "0";
	while (cfg.get("light-reverse-"+istr, cfg_light))
	{
		if (!LoadLight(*cfg_light, content, error_output))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}

		std::stringstream sstr;
		sstr << ++i;
		istr = sstr.str();
	}

	// load car brake/reverse graphics (optional)
	if (cfg.get("light-brake", cfg_light))
	{
		SCENENODE & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_light, bodynoderef, 0, &brakelights))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}
	}
	if (cfg.get("light-reverse", cfg_light))
	{
		SCENENODE & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_light, bodynoderef, 0, &reverselights))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}
	}

	const PTree * cfg_cams;
	if (!cfg.get("camera", cfg_cams))
	{
		return false;
	}
	if (!cfg_cams->size())
	{
		error_output << "No cameras defined." << std::endl;
		return false;
	}
	cameras.reserve(cfg_cams->size());
	for (PTree::const_iterator i = cfg_cams->begin(); i != cfg_cams->end(); ++i)
	{
		CAMERA * cam = LoadCamera(i->second, camerabounce, error_output);
		if (!cam) return false;
		cameras.push_back(cam);
	}

	SetColor(carcolor[0], carcolor[1], carcolor[2]);

	return true;
}
Exemplo n.º 13
0
    /**
     * Loads a matrix from the given stream. The data are written
     * into theChannel, the meta-data are written into theHeader
     * These methods ignore all the parameters in this objects.
     * The only reason they are not static is that they modify
     * the status string.
     */
    bool loadMatrix(const std::string& filename, matrix<T>& theChannel,
                    header& theHeader) {
      theChannel.clear();
      
      //open stream
      std::ifstream in;
      in.open(filename.c_str(),std::ios::in|std::ios::binary);

      //open failed?
      if (!(in.good() && in.is_open())) {
        std::string str = "Could not open file " + filename;
        setStatusString(str.c_str());
        return false;
      }

      // read header
      if (!theHeader.read(in)) {
        setStatusString("Wrong header. Is this an LTI file?");
        return false;
      }

     
      //create the right codec for this file
      dataCodec* codec=0;

      switch (theHeader.encoding.compression) {
        case None: 
          codec=new identityCodec();
          break;
#if HAVE_LIBZ
        case Flate:
          codec=new flateCodec();
          break;
#endif
        case RunLength:
          codec=new runLengthCodec();
          break;
        default: 
          delete codec;
          setStatusString("Unknown codec of libz not installed");
          return false;
      }
      
      
      _lti_debug2("type: " << theHeader.type << std::endl);
      _lti_debug2("encoding.contents: " << theHeader.encoding.contents << std::endl);
      _lti_debug2("encoding.compression: " << theHeader.encoding.compression << std::endl);
      _lti_debug2("size: " << theHeader.size << std::endl);
      _lti_debug2("rows: " << theHeader.rows << std::endl);
      _lti_debug2("columns: " << theHeader.columns << std::endl);
      
      if (theHeader.encoding.compression == None && theHeader.size != 
          (sizeof(T)*theHeader.rows*theHeader.columns)) {
        setStatusString("Inconsistent header.  Wrong file size");
        delete codec;
        return false;
      }
      
      if (theHeader.encoding.contents != getTypeCode(T())) {
        bool flag=true;
        std::string str="Inconsistent file type. ";
        str+=theChannel.getTypeName();
        str+" expected but ";
        // should we really try to recover from type errors???
        // the following compiles, but might not get you what you expect
        switch(theHeader.encoding.contents) {
          case 'b':
            {
              str+=" lti::matrix<ubyte> found.";
              channel8 tmp;
              ioLTIworker<channel8::value_type> worker;
              if (!(flag=worker.loadBody(in,tmp,theHeader,codec))) {
                setStatusString(worker.getStatusString());
              }
              theChannel.castFrom(tmp);
              break;
            }
          case 'i':
            {
              str+=" lti::imatrix found.";
              imatrix tmp;
              ioLTIworker<imatrix::value_type> worker;
              if (!(flag=worker.loadBody(in,tmp,theHeader,codec))) {
                setStatusString(worker.getStatusString());
              }
              theChannel.castFrom(tmp);
              break;
            }
          case 'f':
            {
              str+=" lti::channel found.";
              flag=false;
              //           channel tmp;
              //           flag=loadBody(in,tmp);
              //           // this generates a warning and will probabily generate funny 
              //           // images or channels
              //           theChannel.castFrom(tmp);
              break;
            }
          case 'c':
            {
              // no chance: Forcing an image to something else is task-dependent
              str+=" lti::image found.";
              flag=false;
              //           image tmp;
              //           flag=loadBody(in,tmp);
              //           theChannel.castFrom(tmp);
              break;
            }
          default:
            str+=" unknown type found.";
            flag=false;
        }
        setStatusString(str.c_str());
        in.close();
        delete codec;
        return flag;
      } else {
        bool flag=loadBody(in,theChannel,theHeader,codec);
        in.close();
        delete codec;
        return flag;
      }
      
    }
Exemplo n.º 14
0
bool CarGraphics::Load(
	const PTree & cfg,
	const std::string & carpath,
	const std::string & /*carname*/,
	const std::string & carwheel,
	const std::string & carpaint,
	const Vec3 & carcolor,
	const int anisotropy,
	const float camerabounce,
	ContentManager & content,
	std::ostream & error_output)
{
	assert(!loaded);

	// init drawable load functor
	LoadDrawable loadDrawable(carpath, anisotropy, content, models, textures, error_output);

	// load body first
	const PTree * cfg_body;
	std::string meshname;
	std::vector<std::string> texname;
	if (!cfg.get("body", cfg_body, error_output)) return false;
	if (!cfg_body->get("mesh", meshname, error_output)) return false;
	if (!cfg_body->get("texture", texname, error_output)) return false;
	if (carpaint != "default") texname[0] = carpaint;
	if (!loadDrawable(meshname, texname, *cfg_body, topnode, &bodynode)) return false;

	// load wheels
	const PTree * cfg_wheels;
	if (!cfg.get("wheel", cfg_wheels, error_output)) return false;

	std::shared_ptr<PTree> sel_wheel;
	if (carwheel != "default" && !content.load(sel_wheel, carpath, carwheel)) return false;

	for (PTree::const_iterator i = cfg_wheels->begin(); i != cfg_wheels->end(); ++i)
	{
		const PTree * cfg_wheel = &i->second;

		// override default wheel with selected, not very efficient, fixme
		PTree opt_wheel;
		if (sel_wheel.get())
		{
			opt_wheel.set(*sel_wheel);
			opt_wheel.merge(*cfg_wheel);
			cfg_wheel = &opt_wheel;
		}

		if (!LoadWheel(*cfg_wheel, loadDrawable, topnode, error_output))
		{
			error_output << "Failed to load wheels." << std::endl;
			return false;
		}
	}

	// load drawables
	LoadBody loadBody(topnode, bodynode, loadDrawable);
	for (PTree::const_iterator i = cfg.begin(); i != cfg.end(); ++i)
	{
		if (i->first != "body" &&
			i->first != "steering" &&
			i->first != "light-brake" &&
			i->first != "light-reverse")
		{
			loadBody(i->second);
		}
	}

	// load steering wheel
	const PTree * cfg_steer;
	if (cfg.get("steering", cfg_steer))
	{
		SceneNode & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_steer, bodynoderef, &steernode, 0))
		{
			error_output << "Failed to load steering wheel." << std::endl;
			return false;
		}
		cfg_steer->get("max-angle", steer_angle_max);
		steer_angle_max = steer_angle_max / 180.0 * M_PI;
		SceneNode & steernoderef = bodynoderef.GetNode(steernode);
		steer_orientation = steernoderef.GetTransform().GetRotation();
		steer_rotation = steer_orientation;
	}

	// load brake/reverse light point light sources (optional)
	int i = 0;
	std::string istr = "0";
	const PTree * cfg_light;
	while (cfg.get("light-brake-"+istr, cfg_light))
	{
		if (!LoadLight(*cfg_light, content, error_output))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}

		std::ostringstream sstr;
		sstr << ++i;
		istr = sstr.str();
	}
	i = 0;
	istr = "0";
	while (cfg.get("light-reverse-"+istr, cfg_light))
	{
		if (!LoadLight(*cfg_light, content, error_output))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}

		std::ostringstream sstr;
		sstr << ++i;
		istr = sstr.str();
	}

	// load car brake/reverse graphics (optional)
	if (cfg.get("light-brake", cfg_light))
	{
		SceneNode & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_light, bodynoderef, 0, &brakelights))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}
	}
	if (cfg.get("light-reverse", cfg_light))
	{
		SceneNode & bodynoderef = topnode.GetNode(bodynode);
		if (!loadDrawable(*cfg_light, bodynoderef, 0, &reverselights))
		{
			error_output << "Failed to load lights." << std::endl;
			return false;
		}
	}

	if (!LoadCameras(cfg, camerabounce, error_output))
	{
		return false;
	}

	SetColor(carcolor[0], carcolor[1], carcolor[2]);
	loaded = true;
	return true;
}
FlyEmBodySplitProjectDialog::FlyEmBodySplitProjectDialog(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::FlyEmBodySplitProjectDialog)
{
  ui->setupUi(this);

  m_loadBodyDlg = NULL;

  //connect(this, SIGNAL(accepted()), this, SLOT(clear()));
  connect(ui->view2dBodyPushButton, SIGNAL(clicked()),
          this, SLOT(showData2d()));
  connect(ui->view3dBodyPushButton, SIGNAL(clicked()),
          this, SLOT(showData3d()));
//  connect(ui->viewSplitPushButton,
//          SIGNAL(clicked()), this, SLOT(showResult3d()));
  connect(ui->viewResultQuickPushButton,
          SIGNAL(clicked()), this, SLOT(showResult3dQuick()));
  connect(ui->donePushButton, SIGNAL(clicked()), this, SLOT(clear()));
  connect(ui->loadBodyPushButton, SIGNAL(clicked()), this, SLOT(loadBody()));
  connect(ui->loadBookmarkButton, SIGNAL(clicked()),
          this, SLOT(loadBookmark()));
  /*
  connect(ui->bookmarkVisibleCheckBox, SIGNAL(toggled(bool)),
          &m_project, SLOT(showBookmark(bool)));
          */
  connect(ui->quickViewPushButton, SIGNAL(clicked()), this, SLOT(quickView()));
  connect(ui->fullGrayscaleCheckBox, SIGNAL(toggled(bool)),
          this, SLOT(viewFullGrayscale(bool)));
  connect(ui->updatePushButton, SIGNAL(clicked()),
          this, SLOT(viewFullGrayscale()));
  /*
  connect(ui->prevPushButton, SIGNAL(clicked()),
          this, SLOT(viewPreviousSlice()));
  connect(ui->nextPushButton, SIGNAL(clicked()),
          this, SLOT(viewNextSlice()));
  connect(ui->fullGrayscalePushButton, SIGNAL(clicked()),
          this, SLOT(viewFullGrayscale()));
          */
  connect(ui->saveSeedPushButton, SIGNAL(clicked()),
          this, SLOT(saveSeed()));

  ui->bookmarkView->setModel(&m_bookmarkList);

  updateWidget();

  m_project.setBookmarkVisible(ui->bookmarkVisibleCheckBox->isChecked());

  m_sideViewScene = new QGraphicsScene(this);
  //m_sideViewScene->setSceneRect(0, 0, ui->sideView->width(), ui->sideView->height());
  ui->sideView->setScene(m_sideViewScene);
//  ui->sideView->setFocus();

  setFocusPolicy(Qt::StrongFocus);
  //ui->outputWidget->setText("Load a body to start.");

#ifndef _DEBUG_
  ui->pushButton->hide();
#endif

  m_dvidDlg = ZDialogFactory::makeDvidDialog(this);

  createMenu();
  connectSignalSlot();

  m_messageManager = NULL;
}