void MainWindow::onBodyItemSelectionChanged( ) {
        getSimulationThread().getSimulator().getLock().lockForRead();
        Creature* creature = getSimulationThread().getSimulator().currentCreature();
        if (creature && creature->getNumberOfBodyParts() == getUiInspector().lst_bodies->count()) {
            double mass = 0.0;
            double size_x = 0.0, size_y = 0.0, size_z = 0.0;
            getUiInspector().lst_body_details->clear();
            for (int i = 0; i < getUiInspector().lst_bodies->count(); ++i) {
                if (getUiInspector().lst_bodies->item(i)->isSelected()) {
                    getRendererThread().getRenderer().selectBody(
                            true, creature->getBodyPart(i).getRigidBody());
//                    creature->setSelected(i);
                    {
                        showBodyDetails(*creature, creature->getBodyPart(i));
                        mass += creature->getBodyPart(i).getMass();
                        size_x += creature->getBodyPart(i).getSizeX();
                        size_y += creature->getBodyPart(i).getSizeY();
                        size_z += creature->getBodyPart(i).getSizeZ();
                    }
                } else {
                    getRendererThread().getRenderer().deselectBody(
                            creature->getBodyPart(i).getRigidBody());
                }
            }
            getUiInspector().led_mass->setText(QString(TO_STRING(mass).c_str()));
            getUiInspector().led_size->setText(
                    QString(("[" + TO_STRING(size_x) + " ; " +
                    TO_STRING(size_y) + " ; " + TO_STRING(size_z) + "]").c_str()));
        }
        getSimulationThread().getSimulator().getLock().unlock();
    }
Пример #2
0
    Creature::Creature(int body_parts, int constraints,
            int hidden_layers, int neurons_per_layer)
    :
    _name(""),
    _number_of_body_parts(body_parts),
    _number_of_constraints(constraints),
    _body_parts(new BodyPart*[body_parts]),
    _constraints(new Constraint*[constraints]),
    _neural_network(NULL),
    _initial_position(btVector3(0.0, 0.0, 0.0)),
    _final_position(btVector3(0.0, 0.0, 0.0)),
    _fitness(0.0) {

        for (int i = 0; i < getNumberOfBodyParts(); ++i) {
            setBodyPart(i, new BodyPart());
            getBodyPart(i).setId(i);
            getBodyPart(i).setName("Body Part #" + TO_STRING(i));
        }
        for (int i = 0; i < getNumberOfConstraints(); ++i) {
            setConstraint(i, new Constraint());
            getConstraint(i).setId(i);
            getConstraint(i).setName("Constraint #" + TO_STRING(i));
        }

        _neural_network = new NeuralNetwork(4 * getNumberOfBodyParts(),
                hidden_layers, neurons_per_layer, 3 * (getNumberOfBodyParts() - 1));
        getNeuralNetwork().getInputLayer().setActivationFunction(Neuron::AF_NONE);
        for (int i = 1; i < getNeuralNetwork().getNumberOfLayers(); ++i) {
            getNeuralNetwork().getLayer(i).setActivationFunction(Neuron::AF_TANH);
        }
    }
Пример #3
0
bool FUFileManager::MakeDirectory(const fstring& directory)
{
	FUUri uri(directory);
	fstring absoluteDirectory = uri.GetAbsolutePath();

#ifdef WIN32
	if (_mkdir(TO_STRING(absoluteDirectory).c_str()) == 0) return true;
	errno_t err; _get_errno(&err);
	if (err == EEXIST) return true;
#elif defined(LINUX)
	if (mkdir(TO_STRING(absoluteDirectory).c_str(), ~0u) == 0) return true; // I think this means all permissions..
#elif defined(__APPLE__)
  // begin google modification
  
  assert(0);   // not implemented
  // TODO : the following is wrong - filename needs to be a pascal-string
  // and not a c-string
  //

	// fm::string _fname = TO_STRING(directory);
	// OSErr err = AddFolderDescriptor('extn', 0, 'relf', 0, 0, 0, _fname.c_str(), false);
  
  // end google_modification


#endif // WIN32

	return false;
}
void FUPluginManager::LoadPlugins(const FUObjectType& pluginType)
{
	for (PluginLibraryList::iterator it = loadedLibraries.begin(); it != loadedLibraries.end(); ++it)
	{
#ifndef _DEBUG
		try
#endif // _DEBUG
		{
			DEBUG_OUT("Loading plug-in: %s\n", TO_STRING((*it)->filename).c_str());
			FUAssert((*it)->createPlugin != NULL && (*it)->getPluginType != NULL && (*it)->getPluginCount != NULL, continue);
			uint32 pluginCount = (*((*it)->getPluginCount))();
			for (uint32 i = 0; i < pluginCount; ++i)
			{
				// Retrieve the types of all the plug-ins within this library.
				// Compare them against the wanted types and create the wanted plug-ins.
				const FUObjectType* type = (*((*it)->getPluginType))(i);
				if (type->Includes(pluginType))
				{
					FUPlugin* plugin = (*((*it)->createPlugin))(i);
					if (plugin == NULL) continue;
					loadedPlugins.push_back(plugin);
				}
			}
		}
#ifndef _DEBUG
		catch (...)
		{
			fm::string _filename = TO_STRING((*it)->filename);
			ERROR_OUT("Unhandled exception when loading plugin: %s.", _filename.c_str());
		}
#endif // _DEBUG
	}
}
Пример #5
0
int main ( void )
{
    String stackS = make_string("Test string"),
		   intString = make_string("123"),
		   dblString = make_string(" 12.3"),
           *heapS = new_string("This is on the heap");
    int test_int;
    double test_double;
    S_TO_NUM(intString, &test_int, NUM_INT);
    S_TO_NUM(dblString, &test_double, NUM_DOUBLE);
    destroy_string(
		&intString
	);
	destroy_string(
		&dblString
	);
    printf(
        "%s\n%s\n",
        TO_STRING(stackS),
        P_TO_STRING(heapS)
    );
    printf(
		"String to int test: %d\nString to double test: %f\n",
		test_int,
		test_double
	);
    PREPEND_CHAR(
        &stackS,
        "This is a heap-"
    );
    printf(
        "\nPrepend literal:\n%s\n",
        TO_STRING(stackS)
    );
    CONCAT_CHAR(
        heapS,
        "\nConcat literal"
    );
    printf("\nConcatenated to heap:\n%s\n", P_TO_STRING(heapS));
    CONCAT_CHAR(
        &stackS,
        "\n"
    );
    PREPEND_STRING(
        heapS,
        &stackS
    );
    puts("Prepend string to string:");
    puts(P_TO_STRING(heapS));
    CONCAT_STRING(
        heapS,
        &stackS
    );
    puts("Concatenate strings:");
    printf("%s\n", P_TO_STRING(heapS));
    destroy_string(&stackS);
    delete_string(&heapS);
    return 0;
}
Пример #6
0
void FavoriteMenu::load(QMenu *menu, bool download)
{
    //一旦クリア
    menu->clear();

    QAction *action;
    QByteArray data;
    QFile file(FAVORITE_DOWNLOAD_FILE);
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
    }else{
        QTextStream in(&file);
        in.setCodec("UTF-8");
        while(!in.atEnd()){
            data.append(in.readLine());
        }
        file.close();

        QJsonDocument json = QJsonDocument::fromJson(data);
        QJsonArray array = json.object().value("root").toArray();
        //フォルダ
        for(int i=0; i<array.count(); i++){
            //アイテム
            if(TO_VALUE(array.at(i), "array").isArray()){
                addItem(menu, TO_ARRAY(array.at(i)));
            }else{
//            qDebug() << "title:" << TO_STRING(array->at(i), KEY_TITLE);
                action = menu->addAction(TO_STRING(array.at(i), KEY_TITLE), this, SLOT(clickItem()));
                action->setData(TO_STRING(array.at(i), KEY_URL));
            }
        }

        //現状のデータの日付を保存
        m_currentLoadedFavDataDate = QDate::fromString(json.object().value("serial").toString().left(8), "yyyyMMdd");
//        qDebug() << json.object().value("serial").toString().left(8);
//        qDebug() << "serial=" << serial << "," << serial.toJulianDay();
//        qDebug() << "today =" << QDate::currentDate() << "," << QDate::currentDate().toJulianDay();

    }

    //ユーザー登録ぶん
    QSettings settings(FAV_FILE_NAME, FAV_FILE_FORMAT);
    settings.beginGroup(QStringLiteral(FAV_USER));
    QHash<QString, QVariant> list = settings.value(QStringLiteral(FAV_USER_BOOKMARK)).toHash();
    foreach (const QString &key, list.keys()) {
        action = menu->addAction(list.value(key).toString(), this, SLOT(clickItem()));
        action->setData(key);
    }
    settings.endGroup();


    //お気に入りをダウンロード
    if(download){
        updateFromInternet();
    }
}
void DigitalClock::draw()
{
    string hours = TO_STRING(m_hours);
    string minutes = TO_STRING(m_minutes);
    string seconds = TO_STRING(m_seconds);

    if(hours.size() == 1){hours = "0"+hours;}
    if(minutes.size() == 1){minutes = "0"+minutes;}
    if(seconds.size() == 1){seconds = "0"+seconds;}

    cout <<"I am Digital: "<< hours<<":"<<minutes<<":"<<seconds<<endl;
}
Пример #8
0
  void GnoteSyncClient::write(const std::string & manifest_path)
  {
    sharp::XmlWriter xml(manifest_path);

    try {
      xml.write_start_document();
      xml.write_start_element("", "manifest", "http://beatniksoftware.com/tomboy");

      xml.write_start_element("", "last-sync-date", "");
      xml.write_string(m_last_sync_date.to_iso8601());
      xml.write_end_element();

      xml.write_start_element("", "last-sync-rev", "");
      xml.write_string(TO_STRING(m_last_sync_rev));
      xml.write_end_element();

      xml.write_start_element("", "server-id", "");
      xml.write_string(m_server_id);
      xml.write_end_element();

      xml.write_start_element("", "note-revisions", "");

      for(std::map<std::string, int>::iterator noteGuid = m_file_revisions.begin();
          noteGuid != m_file_revisions.end(); ++noteGuid) {
	xml.write_start_element("", "note", "");
	xml.write_attribute_string("", "guid", "", noteGuid->first);
	xml.write_attribute_string("", "latest-revision", "", TO_STRING(noteGuid->second));
	xml.write_end_element();
      }

      xml.write_end_element(); // </note-revisons>

      xml.write_start_element("", "note-deletions", "");

      for(std::map<std::string, std::string>::iterator noteGuid = m_deleted_notes.begin();
          noteGuid != m_deleted_notes.end(); ++noteGuid) {
	xml.write_start_element("", "note", "");
	xml.write_attribute_string("", "guid", "", noteGuid->first);
	xml.write_attribute_string("", "title", "", noteGuid->second);
	xml.write_end_element();
      }

      xml.write_end_element(); // </note-deletions>

      xml.write_end_element(); // </manifest>
      xml.close();
    }
    catch(...) {
      xml.close();
      throw;
    }
  }
Пример #9
0
const int salad_predict_callback(data_t* data, const size_t n, void* const usr)
{
	assert(data != NULL);
	assert(n > 0);
	assert(usr != NULL);

	predict_t* const x = (predict_t*) usr;

	struct timeval start, end;
	gettimeofday(&start, NULL);

	for (size_t i = 0; i < n; i++)
	{
		x->scores[i] = x->fct(&x->param, data[i].buf, data[i].len);
	}

	// Clock the calculation procedure
	gettimeofday(&end, NULL);
	double diff = TO_SEC(end) -TO_SEC(start);
	x->totalTime += diff;

	// Write scores
	char buf[0x100];

#ifdef GROUPED_INPUT
	if (x->config->group_input)
	{
		group_t* prev = data[0].meta;
		fputs(TO_STRING(x->scores[0]), x->fOut);

		for (size_t j = 1; j < n; j++)
		{
			fputs(prev == data[j].meta ? " " : "\n", x->fOut);
			fputs(TO_STRING(x->scores[j]), x->fOut);
			prev = data[j].meta;
		}
	}
	else
#endif
	{
		for (size_t j = 0; j < n; j++)
		{
			fputs(TO_STRING(x->scores[j]), x->fOut);
			fputs("\n", x->fOut);
		}
	}
	return EXIT_SUCCESS;
}
Пример #10
0
bool FArchiveXML::LoadEntityInstance(FCDObject* object, xmlNode* instanceNode)
{ 
	FCDEntityInstance* entityInstance = (FCDEntityInstance*)object;

	bool status = true;

	FUUri uri = ReadNodeUrl(instanceNode);
	entityInstance->GetEntityReference()->SetUri(uri);
	if (!entityInstance->IsExternalReference() && entityInstance->GetEntity() == NULL)
	{
		FUError::Error(FUError::WARNING_LEVEL, FUError::WARNING_INST_ENTITY_MISSING, instanceNode->line);
	}

	entityInstance->SetWantedSubId(TO_STRING(ReadNodeSid(instanceNode)));
	entityInstance->SetName(TO_FSTRING(ReadNodeName(instanceNode)));

	// Read in the extra nodes
	xmlNodeList extraNodes;
	FindChildrenByType(instanceNode, DAE_EXTRA_ELEMENT, extraNodes);
	for (xmlNodeList::iterator it = extraNodes.begin(); it != extraNodes.end(); ++it)
	{
		xmlNode* extraNode = (*it);
		FArchiveXML::LoadExtra(entityInstance->GetExtra(), extraNode);
	}

	entityInstance->SetDirtyFlag(); 
	return status;
}
Пример #11
0
 virtual void evaluate( const FunctionNode& function ) {
     return;
     return;
     switch (function.getType()) {
         case FunctionNode::FT_MOVE :
         {
             //suma
             //                    int result = 0;
             //                    for (int i = 0; i < arity - 1; ++i) {
             //                        result += arguments[i]->getValue();
             //                    }
             //                    arguments[arity - 1]->setValue(result);
             //                    std::cout << function.toString() << std::endl;
             break;
         }
         case FunctionNode::FT_SWAP :
         {
             //resta
             //                    int result = 0;
             //                    for (int i = 0; i < arity - 1; ++i) {
             //                        result -= arguments[i]->getValue();
             //                    }
             //                    arguments[arity - 1]->setValue(result);
             break;
         }
         default: DEBUGM(TO_STRING(function.getType()));
             assert(0);
     }
 }
Пример #12
0
 void GpModel::step( ) {
     TreeOfNodes** next = new TreeOfNodes*[getPopulationSize()];
     eGeneticOperator go = GO_NONE;
     for (int i = 0; i < getPopulationSize(); ++i) {
         go = nextGeneticOperator();
         switch (go) {
             case GO_CROSSOVER:
             {
                 TreeOfNodes* offspring = bestTournament().clone();
                 getCrossoverOperator()->crossover(*offspring, bestTournament());
                 next[i] = offspring;
             }
                 break;
             case GO_REPRODUCTION:
                 next[i] = getReproductionOperator()->reproduce(bestTournament());
                 break;
             case GO_MUTATION:
                 next[i] = getMutationOperator()->mutate(bestTournament(1), getTreeGenerator());
                 break;
             default:
                 BDEBUG(TO_STRING(go));
                 assert(0);
         }
     }
     for (int i = 0; i < getPopulationSize(); ++i) {
         delete _trees[i];
     }
     delete _trees;
     _trees = next;
 }
Пример #13
0
int
__pmPMCDAddPorts(int **ports, int nports)
{
    /*
     * The list of ports referenced by *ports may be (re)allocated
     * using calls to realloc(3) with a new size based on nports.
     * For an empty list, *ports must be NULL and nports must be 0.
     * It is the responsibility of the caller to free this memory.
     *
     * This function is guaranteed to return a list containing at least
     * 1 element.
     */
    char *env;
    int  new_nports = nports;

    if ((env = getenv("PMCD_PORT")) != NULL)
	new_nports = __pmAddPorts(env, ports, nports);

    /*
     * Add the default port, if no new ports were added or if there was an
     * error.
     */
    if (new_nports <= nports)
	new_nports = __pmAddPorts(TO_STRING(SERVER_PORT), ports, nports);

    return new_nports;
}
Пример #14
0
 T * GetRoutineAs()
 {
   ASSERT(m_routine.get(), ("Routine is not set"));
   T * ptr = dynamic_cast<T *>(m_routine.get());
   ASSERT(ptr, ("Can't convert IRoutine* to", TO_STRING(T) "*"));
   return ptr;
 }
    BodyPart::eShape EvolutionOfMorphologyAndBehavior::getShape(double value) {
        //[0.0, 10.0) -> BOX
        //[10.0, 20.0) -> SPHERE
        //[20.0, 30.0) -> CAPSULE
        //[30.0, 40.0) -> CONE
        //[40.0, 50.0) -> CYLINDER
        //[50.0, 60.0) -> BOX
        //[60.0, 70.0) -> SPHERE
        //[70.0, 80.0) -> CAPSULE
        //[80.0, 90.0) -> CONE
        //[90.0, 100.0) -> CYLINDER

        if (value >= 0.0 && value < 20.0) {
            return BodyPart::S_BOX;
        }

        if (value >= 20.0 && value < 40.0) {
            return BodyPart::S_SPHERE;
        }

        if (value >= 40.0 && value < 60.0) {
            double p = 20.0 / 3.0; //Portion
            if (value >= 40.0 && value < 40.0 + p) {
                return BodyPart::S_CAPSULE_X;
            }
            if (value >= 40.0 + p && value < 40.0 + (2 * p)) {
                return BodyPart::S_CAPSULE_Y;
            }
            if (value >= 40.0 + (2 * p) && value < 60.0) {
                return BodyPart::S_CAPSULE_Z;
            }
        }

        if (value >= 60.0 && value < 80.0) {
            double p = 20.0 / 3.0; //Portion
            if (value >= 60.0 && value < 60.0 + p) {
                return BodyPart::S_CONE_X;
            }
            if (value >= 60.0 + p && value < 60.0 + (2 * p)) {
                return BodyPart::S_CONE_Y;
            }
            if (value >= 60.0 + (2 * p) && value < 80.0) {
                return BodyPart::S_CONE_Z;
            }
        }
        if (value >= 80.0 && value < 100.0) {
            double p = 20.0 / 3.0; //Portion
            if (value >= 80.0 && value < 80.0 + p) {
                return BodyPart::S_CYLINDER_X;
            }
            if (value >= 80.0 + p && value < 80.0 + (2 * p)) {
                return BodyPart::S_CYLINDER_Y;
            }
            if (value >= 80.0 + (2 * p) && value < 100.0) {
                return BodyPart::S_CYLINDER_Z;
            }
        }
        BDEBUG(TO_STRING(value));
        assert(0);
    }
Пример #16
0
QStealthTableView::QStealthTableView(QWidget *parent) :
    QScrollArea(parent),
    header(0),
    fShowHeader(true)
{
    this->horizontalScrollBar()->setDisabled(true);
    this->horizontalScrollBar()->hide();
    this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    lblBack = new QLabel(this);
    lblBack->setStyleSheet("QLabel {background-color: #ccc; border: none;}");
    table = new QTableView(lblBack);
    this->setWidget(lblBack);

    QtCellItemDelegate *delegate = new QtCellItemDelegate(this);
    table->setItemDelegate(delegate);

    table->setSelectionBehavior(QAbstractItemView::SelectRows);
    table->horizontalHeader()->hide();
    table->verticalHeader()->hide();
    table->setAlternatingRowColors(true);
    table->setAutoScroll(false);
    table->setShowGrid(false);
    table->setWordWrap(false);
    table->setCornerButtonEnabled(false);
    table->setFocusPolicy(Qt::NoFocus);
    table->setSelectionMode(QAbstractItemView::SingleSelection);
    table->verticalHeader()->setDefaultSectionSize(40);
    table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    table->horizontalScrollBar()->setDisabled(true);
    table->verticalScrollBar()->setDisabled(true);

    QString qss = SC_QSS_TOOLTIP_DEFAULT;
    qss += "QTableView {   border: none;"
                         " selection-color: #fff;"
                         " selection-background-color: #3cabe1;"
                         " background-color: #fff;"
                         " font-size: " + QString(TO_STRING(SC_TABLE_FONT_PX)) + "px;"
                         " alternate-background-color: #e8e8e8; }";

    table->setStyleSheet(qss);
#if 1
    this->setStyleSheet("border: none; background-color: #ccc;");

    qss = "";
    qss += "QScrollBar::handle:vertical{background-color: #3e3e41; min-height:40px;}";
    qss += "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical{background-color: #999;}";
    this->verticalScrollBar()->setStyleSheet(qss);

    this->lblBack->setStyleSheet("QLineEdit {background-color: white; border: 1px solid #999;}");
#else
    qss = "QStealthTableView {border: none; background-color: #ccc;}";
    this->setStyleSheet(qss);

    qss = "";
    qss += "QScrollBar::handle:vertical{background-color: #3e3e41; min-height:40px;}";
    qss += "QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical{background-color: #999;}";
    this->verticalScrollBar()->setStyleSheet(qss);
#endif
}
Пример #17
0
bool FArchiveXML::LoadGeometryInstance(FCDObject* object, xmlNode* instanceNode)
{
	if (!FArchiveXML::LoadEntityInstance(object, instanceNode)) return false;

	bool status = true;
	FCDGeometryInstance* geometryInstance = (FCDGeometryInstance*)object;

	// Look for the <bind_material> element. The others are discarded for now.
	xmlNode* bindMaterialNode = FindChildByType(instanceNode, DAE_BINDMATERIAL_ELEMENT);
	if (bindMaterialNode != NULL)
	{
		for (xmlNode* child = bindMaterialNode->children; child != NULL; child = child->next)
		{
			if (child->type != XML_ELEMENT_NODE) continue;

			if (IsEquivalent(child->name, DAE_PARAMETER_ELEMENT))
			{
				FCDEffectParameter* parameter = geometryInstance->AddEffectParameter(FArchiveXML::GetEffectParameterType(child));
				parameter->SetAnimator();
				status &= FArchiveXML::LoadSwitch(parameter, &parameter->GetObjectType(), child);
			}
		} 

		// Retrieve the list of the <technique_common><instance_material> elements.
		xmlNode* techniqueNode = FindChildByType(bindMaterialNode, DAE_TECHNIQUE_COMMON_ELEMENT);
		xmlNodeList materialNodes;
		FindChildrenByType(techniqueNode, DAE_INSTANCE_MATERIAL_ELEMENT, materialNodes);
		for (xmlNodeList::iterator itM = materialNodes.begin(); itM != materialNodes.end(); ++itM)
		{
			FCDMaterialInstance* material = geometryInstance->AddMaterialInstance();
			status &= (FArchiveXML::LoadMaterialInstance(material, *itM));
		}
	}
	else
	{
		// Blinding attempt to use the material semantic from the polygons as a material id.
		FCDGeometry* geometry = (FCDGeometry*) geometryInstance->GetEntity();
		if (geometry != NULL && geometry->HasType(FCDGeometry::GetClassType()) && geometry->IsMesh())
		{
			FCDGeometryMesh* mesh = geometry->GetMesh();
			size_t polyCount = mesh->GetPolygonsCount();
			for (size_t i = 0; i < polyCount; ++i)
			{
				FCDGeometryPolygons* polys = mesh->GetPolygons(i);
				const fstring& semantic = polys->GetMaterialSemantic();
				fm::string semanticUTF8 = TO_STRING(semantic);
				semanticUTF8 = FCDObjectWithId::CleanId(semanticUTF8.c_str());
				FCDMaterial* material = geometry->GetDocument()->FindMaterial(semanticUTF8);
				if (material != NULL)
				{
					geometryInstance->AddMaterialInstance(material, polys);
				}
			}
		}
	}

	geometryInstance->SetDirtyFlag();
	return status;
}
Пример #18
0
 std::string TreeOfNodes::toString() const {
     std::string result = "Tree={f=" + TO_STRING(getFitness()) + ";";
     if (getRoot()) {
         result += getRoot()->toString();
     }
     result += "}";
     return result;
 }
Пример #19
0
bool FUFileManager::MakeDirectory(const fstring& directory)
{
	FUUri uri(directory);
	fstring absoluteDirectory = uri.GetAbsolutePath();

#ifdef WIN32
	if (_mkdir(TO_STRING(absoluteDirectory).c_str()) == 0) return true;
	errno_t err; _get_errno(&err);
	if (err == EEXIST) return true;
#elif defined(LINUX)
	if (mkdir(TO_STRING(absoluteDirectory).c_str(), ~0u) == 0) return true; // I think this means all permissions..
#elif defined(__APPLE__)
	fm::string _fname = TO_STRING(directory);
	OSErr err = AddFolderDescriptor('extn', 0, 'relf', 0, 0, 0,(const unsigned char*) _fname.c_str(), false);
#endif // WIN32

	return false;
}
Пример #20
0
void 
CheckForGLError( const std::string &situation  )
{
	GLenum errorCode = glGetError();
	if (errorCode != GL_NO_ERROR) {
		const char *string = (const char *)gluErrorString(errorCode);
		_THROW_ GLException( TO_STRING( situation << " : " << string ) );
	}
}
Пример #21
0
    void BasicDebug::debug( double init_value ) {
        if (init_value >= 0.0) {
            SEQUENCE = init_value;
        }
#ifdef DEBUG_TO_LOG
        LOGP(TO_STRING(SEQUENCE++));
#else
        std::cout << SEQUENCE++ << std::endl;
#endif
    }
Пример #22
0
    void BasicDebug::debug( const std::string& message, double init_value ) {
        if (init_value >= 0.0) {
            SEQUENCE = init_value;
        }
#ifdef DEBUG_TO_LOG
        LOGP(TO_STRING(SEQUENCE++) + " : " + message);
#else
        std::cout << SEQUENCE++ << " : " << message << std::endl;
#endif
    }
Пример #23
0
static void __inline initializeLogger(const unsigned int n)  {
    const int logstat = LOG_PID|LOG_TID|LOG_RDTSC|LOG_FILE_SYNC_ON_ERRORS_ONLY;
    const int logfac = LOG_USER;
    const char *identity = program;

    if (strcmp(TO_STRING(LOGGER),"threadFileLogger") == 0) {
    	char threadIdentity[PATH_MAX];
    	sprintf(threadIdentity,"%s.%d",identity,n);
    	openLogThreadFile(threadIdentity,logstat,logfac);
    	setThreadFileLoggerMaxSize(4 * 1024 * 1024);
    	DEBUG_VAR(threadIdentity,"%s");
    } else if (strcmp(TO_STRING(LOGGER),"syslogex") == 0) {
        openlogex(identity, logstat, logfac);
    } else if (strcmp(TO_STRING(LOGGER),"fileLogger") == 0) {
        openLogFile(program, logstat, logfac);
        setFileLoggerMaxSize(4 * 1024 * 1024);
    } else if (strcmp(TO_STRING(LOGGER),"consoleLogger") == 0) {
        setConsoleLoggerOpt(program, logstat, logfac);
    }
}
Пример #24
0
BFP_TYPE
DFP_TO_BFP (DFP_C_TYPE f)
{
  IEEE_TYPE s;
  char buf[BUFMAX];

  HOST_TO_IEEE (f, &s);
  /* Write the value to a string.  */
  TO_STRING (&s, buf);
  /* Read it as the binary floating point type and return that.  */
  return STR_TO_BFP (buf, NULL);
}
Пример #25
0
    Creature * Creature::fromXml(const std::string& xml, bool* ok) {
        QDomDocument doc;
        QString * error_msg = new QString();
        int* error_line = new int();
        int* error_col = new int();
        *ok = doc.setContent(QString(xml.c_str()), error_msg, error_line, error_col);
        if (!*ok) {
            BDEBUG("Error: " + error_msg->toStdString() +
                    " at [" + TO_STRING(*error_line) + " , " +
                    TO_STRING(*error_col) + "]");
        }
        delete error_msg;
        delete error_line;
        delete error_col;
        if (!*ok) {
            return NULL;
        }
        QDomElement root = doc.firstChild().toElement();

        return fromXml(root, ok);
    }
Пример #26
0
    void Creature::toXml(QDomDocument& xml, QDomElement * parent) const {
        QDomElement creature = xml.createElement("Creature");

        //        creature.setAttribute("id", getId());
        creature.setAttribute("name", QString(getName().c_str()));
        //        creature.setAttribute("type", QString::number(getType()));
        creature.setAttribute("body-parts", getNumberOfBodyParts());
        creature.setAttribute("constraints", getNumberOfConstraints());
        creature.setAttribute("hidden-layers", getNeuralNetwork().getNumberOfLayers() - 2);
        creature.setAttribute("neurons-per-layer", getNeuralNetwork().getLayer(1).getNumberOfNeurons());
        creature.setAttribute("initial-position", QString((
                TO_STRING(getInitialPosition().x()) + " ; " +
                TO_STRING(getInitialPosition().y()) + " ; " +
                TO_STRING(getInitialPosition().z())).c_str()));
        creature.setAttribute("final-position", QString((
                TO_STRING(getFinalPosition().x()) + " ; " +
                TO_STRING(getFinalPosition().y()) + " ; " +
                TO_STRING(getFinalPosition().z())).c_str()));
        creature.setAttribute("fitness", getFitness());

        for (int i = 0; i < getNumberOfBodyParts(); ++i) {
            getBodyPart(i).toXml(xml, &creature);
        }
        for (int i = 0; i < getNumberOfConstraints(); ++i) {
            getConstraint(i).toXml(xml, &creature);
        }
        getNeuralNetwork().toXml(xml, &creature);
        if (parent) {
            parent->appendChild(creature);
        } else {

            xml.appendChild(creature);
        }
    }
    void MainWindow::showBodyDetails( const Creature& creature, const BodyPart& body ) {
        getUiInspector().lst_body_details->addItem(QString(
                body.getName().c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  Mass: " + TO_STRING(body.getMass())).c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  Torque: " + TO_STRING(body.getMaxTorque())).c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                std::string("  Size").c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  [x]: " + TO_STRING(body.getSizeX())).c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  [y]: " + TO_STRING(body.getSizeY())).c_str()));
        getUiInspector().lst_body_details->addItem(QString(
                ("  [z]: " + TO_STRING(body.getSizeZ())).c_str()));
        //Angles

        BodyPart* parent = body.getParentId() == Creature::B_NONE
                ? NULL : &creature.getBodyPart(body.getParentId());
        if (parent) {
            getUiInspector().lst_body_details->addItem(QString(
                    ("  Parent: " + parent->getName()).c_str()));
            //            getUiInspector().lst_body_details->addItem(QString(std::string("  Angles:").c_str()));
            //            getUiInspector().lst_body_details->addItem(QString(
            //                    ("   XY:" + TO_STRING(
            //                    MathUtil::getAngle(MathUtil::XY,
            //                    parent->getRigidBody()->getCenterOfMassPosition(),
            //                    body.getRigidBody()->getCenterOfMassPosition()))).c_str()));
            //            getUiInspector().lst_body_details->addItem(QString(
            //                    ("   YZ:" + TO_STRING(
            //                    MathUtil::getAngle(MathUtil::YZ,
            //                    parent->getRigidBody()->getCenterOfMassPosition(),
            //                    body.getRigidBody()->getCenterOfMassPosition()))).c_str()));
            //            getUiInspector().lst_body_details->addItem(QString(
            //                    ("   ZX:" + TO_STRING(
            //                    MathUtil::getAngle(MathUtil::ZX,
            //                    parent->getRigidBody()->getCenterOfMassPosition(),
            //                    body.getRigidBody()->getCenterOfMassPosition()))).c_str()));
        }
    }
Пример #28
0
void
MainManager::SaveResultDatasets()
{
	QString name = QFileDialog::getSaveFileName();

	Path maskName = TO_STRING( name.toStdString() << "Mask.dump" );
	Path dataName = TO_STRING( name.toStdString() << "Data.dump" );
	Path indexName = TO_STRING( name.toStdString() << ".idx" );

	M4D::Imaging::ImageFactory::DumpImage( maskName.file_string(), *_tmpMask );
	M4D::Imaging::ImageFactory::DumpImage( dataName.file_string(), *_tmpImage );

	std::ofstream indexFile( indexName.file_string().data() );

	indexFile << dataName.filename() << std::endl;
	indexFile << maskName.filename() << std::endl;

	indexFile.close();
	
	QMessageBox::information( NULL, "Saving finished", "Results saved" );

}
Пример #29
0
    Creature::Creature(int body_parts, int constraints, const NeuralNetwork & neural_network)
    :
    _name(""),
    _number_of_body_parts(body_parts),
    _number_of_constraints(constraints),
    _body_parts(new BodyPart*[body_parts]),
    _constraints(new Constraint*[constraints]),
    _neural_network(NULL),
    _initial_position(btVector3(0.0, 0.0, 0.0)),
    _final_position(btVector3(0.0, 0.0, 0.0)),
    _fitness(0.0) {
        for (int i = 0; i < getNumberOfBodyParts(); ++i) {
            setBodyPart(i, new BodyPart());
            getBodyPart(i).setName("Body Part #" + TO_STRING(i));
        }
        for (int i = 0; i < getNumberOfConstraints(); ++i) {
            setConstraint(i, new Constraint());
            getConstraint(i).setName("Constraint #" + TO_STRING(i));
        }

        setNeuralNetwork(neural_network.clone());
    }
Пример #30
0
int main(int argc, char *argv[])
{
   if (argc != 2) {
      std::cerr << "tutorial version " TO_STRING(TUTORIAL_VERSION_MAJOR) "." TO_STRING(TUTORIAL_VERSION_MINOR) "\n"
         "Usage: " << argv[0] << " num" << std::endl;
      return EXIT_FAILURE;
   }
   char *p;
   double num = std::strtod(argv[1], &p);
   if (p[strspn(p, " \t\n")] != '\0' || p == argv[1]) {
      std::cerr << "Error with argument" << std::endl;
      return EXIT_FAILURE;
   }

#ifdef MYSQRT
   num = mysqrt(num);
#else
   num = sqrt(num);
#endif

   std::cout << std::setprecision(std::numeric_limits<double/*decltype(num)*/>::max_digits10) << num << std::endl;
   
   return EXIT_SUCCESS;
}