コード例 #1
0
ファイル: G3D.cpp プロジェクト: BlueBrain/TuvokIO
void G3D::convertVertices(const float * const vertices, std::vector<float*> & vertexAttributes, const GeometryInfo & info)
{
	uint32_t i = 0;
	for (std::vector<uint32_t>::const_iterator it=info.attributeSemantics.begin(); it!=info.attributeSemantics.end(); ++it)
	{
		vertexAttributes.push_back(NULL);
		uint32_t attributeFloats = floats(*it);
		vertexAttributes.at(i) = new float[info.numberVertices * attributeFloats];
		++i;
	}

	uint32_t vertexFloats = info.vertexSize / sizeof(float);
	for (uint32_t i=0; i<info.numberVertices; ++i)
	{
		uint32_t offset = 0;
		uint32_t attributeIndex = 0;
		for (std::vector<uint32_t>::const_iterator it=info.attributeSemantics.begin(); it!=info.attributeSemantics.end(); ++it)
		{
			uint32_t attributeFloats = floats(*it);
			for (uint32_t j=0; j<attributeFloats; ++j) vertexAttributes[attributeIndex][j + (i * attributeFloats)] = vertices[j + offset + (i * vertexFloats)];
			offset += attributeFloats;
			++attributeIndex;
		}
	}
}
コード例 #2
0
void Foam::tecplotWriter::writeField(const Field<Type>& fld) const
{
    for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
    {
        scalarField cmptFld(fld.component(cmpt));

        // Convert to float
        Field<float> floats(cmptFld.size());
        forAll(cmptFld, i)
        {
            floats[i] = float(cmptFld[i]);
        }

        INTEGER4 size = INTEGER4(floats.size());
        INTEGER4 IsDouble = 0;  //float

        //Pout<< "Writing component:" << cmpt << " of size:" << size
        //    << " floats." << endl;

        if (!TECDAT112(&size, floats.begin(), &IsDouble))
        {
//            FatalErrorIn("tecplotWriter::writeField(..) const")
//                << "Error in TECDAT112." << exit(FatalError);
        }
    }
}
コード例 #3
0
ファイル: G3D.cpp プロジェクト: BlueBrain/TuvokIO
void G3D::print(const Geometry * const geometry, std::ostream & output)
{
	if (geometry)
	{
		output << "Opaque: " << (geometry->info.isOpaque ? "yes" : "no") << std::endl;
		output << "Number primitives: " << geometry->info.numberPrimitives << std::endl;
		output << "Primitive type: " << ((geometry->info.primitiveType == Point) ? "Point" : 
				(geometry->info.primitiveType == Line) ? "Line" :
				(geometry->info.primitiveType == Triangle) ? "Triangle" :
				(geometry->info.primitiveType == TriangleAdj) ? "Triangle with adjacency" : "Unknown") << std::endl;
		output << "Number indices: " << geometry->info.numberIndices << std::endl;
		output << "Index size: " << geometry->info.indexSize << std::endl;
		output << "Number vertices: " << geometry->info.numberVertices << std::endl;
		output << "Vertex size: " << geometry->info.vertexSize << std::endl;
		output << "Vertex type: " << ((geometry->info.vertexType == AoS) ? "Array of Structs" : 
				(geometry->info.vertexType == SoA) ? "Struct of Arrays" : "Unknown") << std::endl;
		output << "Vertex attribute semantics:" << std::endl;
		for (std::vector<uint32_t>::const_iterator it=geometry->info.attributeSemantics.begin(); it!=geometry->info.attributeSemantics.end(); ++it)
		{
			output << "\t" << (((*it) == Position) ? "Position" : 
				((*it) == Normal) ? "Normal" :
				((*it) == Tangent) ? "Tangent" :
				((*it) == Color) ? "Color" :
				((*it) == Tex) ? "Tex" :
				((*it) == Float) ? "Float" : "Unknown") << " (" << floats(*it) << "f)" << std::endl;
		}
	}
}
コード例 #4
0
ファイル: G3D.cpp プロジェクト: SCIInstitute/SCIRun
void G3D::writeVertexAttributes(AbstractWriter& writer, const std::vector<std::vector<float>>& vertexAttributes, const GeometryInfo& info) {
    uint32_t i = 0;
    for (auto semantic : info.attributeSemantics) {
        writer.write((char*)vertexAttributes.at(i).data(), info.numberVertices * floats(semantic) * sizeof(float));
        ++i;
    }
}
コード例 #5
0
 void GpuParticles::load(const string& fileName)
 {
     ifstream fileStream(ofToDataPath(fileName, true).c_str());
     if (fileStream.is_open())
     {
         string data((istreambuf_iterator<char>(fileStream)), std::istreambuf_iterator<char>());
         vector<string> textureData = ofSplitString(data, "|");
         for (unsigned i = 0; i < textureData.size(); ++i)
         {
             if (i < fbos[currentReadFbo].getNumTextures())
             {
                 vector<string> floatsAsText = ofSplitString(textureData[i], ",");
                 vector<float> floats(floatsAsText.size(), 0);
                 for (unsigned j = 0; j < floats.size(); ++j)
                 {
                     floats[j] = atof(floatsAsText[j].c_str());
                 }
                 loadDataTexture(i, &floats[0]);
             }
             else ofLogError() << "Trying to load data from file into non-existent buffer.";
         }
         fileStream.close();
     }
     else ofLogError() << "Could not load particle data from " << ofToDataPath(fileName, true);
 }
コード例 #6
0
ファイル: G3D.cpp プロジェクト: BlueBrain/TuvokIO
void G3D::writeVertices(std::fstream & fs, const std::vector<float*> & vertexAttributes, const GeometryInfo & info)
{
	uint32_t i = 0;
	for (std::vector<uint32_t>::const_iterator it=info.attributeSemantics.begin(); it!=info.attributeSemantics.end(); ++it) 
	{
		fs.write((char*)vertexAttributes.at(i), info.numberVertices * floats(*it) * sizeof(float));
		++i;
	}
}
コード例 #7
0
ファイル: TupleObj.cpp プロジェクト: atlas-org/gaudi
// ============================================================================
StatusCode Tuples::TupleObj::column ( const std::string& name   ,
                                      const float        value  )
{
  if ( invalid() ) { return InvalidTuple  ; }
  Float* item = floats ( name ) ;
  if ( !item )     { return InvalidColumn ; }
  *item = value ;
  return StatusCode::SUCCESS ;
}
コード例 #8
0
ファイル: G3D.cpp プロジェクト: SCIInstitute/SCIRun
std::vector<std::vector<float>> G3D::readVertexAttributes(AbstractReader& reader, const GeometryInfo& info) {
    std::vector<std::vector<float>> vertexAttributes;
    for (uint32_t i = 0; i < info.attributeSemantics.size(); ++i) {
        uint32_t attributeFloats = floats(info.attributeSemantics.at(i));
        std::vector<float> attibutes(info.numberVertices * attributeFloats);
        vertexAttributes.push_back(attibutes);
        reader.read((char*)vertexAttributes.at(i).data(), info.numberVertices * attributeFloats * sizeof(float));
    }
    return vertexAttributes;
}
コード例 #9
0
ファイル: G3D.cpp プロジェクト: BlueBrain/TuvokIO
void G3D::readVertices(std::fstream & fs, std::vector<float*> & vertexAttributes, const GeometryInfo & info)
{
	for (uint32_t i=0; i<info.attributeSemantics.size(); ++i) 
	{
		vertexAttributes.push_back(NULL);
		uint32_t attributeFloats = floats(info.attributeSemantics.at(i));
		vertexAttributes.at(i) = new float[info.numberVertices * attributeFloats];
		fs.read((char*)vertexAttributes.at(i), info.numberVertices * attributeFloats * sizeof(float));
	}
}
コード例 #10
0
ファイル: G3D.cpp プロジェクト: SCIInstitute/SCIRun
std::vector<std::vector<float>> G3D::convertVertices(const std::vector<float>& vertices, const GeometryInfo& info) {
    std::vector<std::vector<float>> vertexAttributes;
    for (auto semantic : info.attributeSemantics) {
        uint32_t attributeFloats = floats(semantic);
        vertexAttributes.push_back(std::vector<float>(info.numberVertices * attributeFloats));
    }

    uint32_t vertexFloats = info.vertexSize / sizeof(float);
    for (uint32_t i = 0; i < info.numberVertices; ++i) {
        uint32_t offset = 0;
        uint32_t attributeIndex = 0;
        for (std::vector<uint32_t>::const_iterator it = info.attributeSemantics.begin(); it != info.attributeSemantics.end(); ++it) {
            uint32_t attributeFloats = floats(*it);
            for (uint32_t j = 0; j < attributeFloats; ++j)
                vertexAttributes[attributeIndex][j + (i * attributeFloats)] = vertices[j + offset + (i * vertexFloats)];
            offset += attributeFloats;
            ++attributeIndex;
        }
    }
    return vertexAttributes;
}
コード例 #11
0
ファイル: primitives.cpp プロジェクト: jcayzac/androido3d
void Primitives::SetFieldFromVector3s(
  o3d::FloatField* field,
  const std::vector<o3d::Vector3>& vectors) {
  scoped_array<float> floats(new float[vectors.size() * 3]);
  for (size_t ii = 0; ii < vectors.size(); ++ii) {
    size_t off = ii * 3;
    const o3d::Vector3& src = vectors[ii];
    floats[off + 0] = src[0];
    floats[off + 1] = src[1];
    floats[off + 2] = src[2];
  }
  field->SetFromFloats(floats.get(), 3, 0, vectors.size());
}
コード例 #12
0
ファイル: G3D.cpp プロジェクト: SCIInstitute/SCIRun
std::string G3D::printAttributeSemantics(const Geometry& geometry) {
    std::string as;
    for (size_t i = 0; i < geometry.info.attributeSemantics.size(); ++i) {
        if (i)
            as.append(", ");
        auto const& it = geometry.info.attributeSemantics[i];
        as.append(((it) == Position)
                      ? "Position"
                      : ((it) == Normal) ? "Normal"
                                         : ((it) == Tangent)
                                               ? "Tangent"
                                               : ((it) == Color) ? "Color" : ((it) == Tex) ? "Tex" : ((it) == Float) ? "Float" : "Unknown");
        as.append(" (" + std::to_string(floats(it)) + "f)");
    }
    return as;
}
コード例 #13
0
ファイル: main.cpp プロジェクト: cmosnick/hpc-work
// Read csv into map of vectors
int read_in_file(map< string, vector<float> > *files, FILE *infile, map<string, uint> &fnames, vector< pair< uint, vector<float> > > &lines){
	if(files && infile){
		char *line = (char*)malloc(sizeof(char) * LINE_SIZE);
		char *token = NULL;

		// Get line
		size_t lineSize = LINE_SIZE;
		int numLines = 0;
		while(getline(&line, &lineSize, infile)){
			
			// Get first token, the filename
			token = strtok(line, DELIMS);
			if(token){
				// Put token into string
				std::string fname (token);
				fnames[fname] = numLines;

				// read in floats
				vector<float> floats(NUM_FLOATS);
				uint i = 0;
				do{
					token = strtok(NULL, DELIMS);
					if(token && is_float(token)){
						float temp = atof(token);
						floats[i]=temp;
					}
					else 
						break;
					i++;
				}while( i <= NUM_FLOATS);

				// Add fname and vector to map
				(*files)[fname] = floats;
				pair <uint, vector<float> > temp(numLines, floats);
				lines.push_back(temp);
			}
			else{
				break;
			}
			numLines ++;
		}
		free(line);

		return numLines;
	}
	return 0;
}
コード例 #14
0
ファイル: remote.cpp プロジェクト: gizatt/xen_quad
/** 
 * Manages comms with the gamepad controller and translates that into motor commands
 * to send to quad.
 */
int main(int argc, char **argv)
{
  int i;
  ros::init(argc, argv, "xq_remote");
  ros::NodeHandle n;
  ros::Publisher chatter_pub = n.advertise<std_msgs::Float32MultiArray>("xen_quad_motor_chatter", 1000);
  ros::Subscriber imu_listener = n.subscribe("xen_quad_imu_chatter", 1000, imuChatterCallback);

  /* Open log file */
  log_file = fopen("/home/gizatt/xen_quad_log.csv", "a");
  if (log_file == NULL){
    ROS_ERROR("XEN_QUAD: Couldn't open log file!");
    return 1;
  }
  fprintf(log_file, "\n\n*********************************************\n");
  fprintf(log_file, "**************** NEW SESSION ****************\n");
  fflush(log_file);

  /* Create joystick listener */
  ros::Subscriber sub = n.subscribe<sensor_msgs::Joy>("joy", 10, joyCallback);

  ros::Rate loop_rate(LOOP_RATE_HZ);
   
  int iter = 0;
  while (ros::ok())
  {
    /* Create this loop's message */
    std_msgs::Float32MultiArray msg;
    /* Populate */
    std::vector<float> floats(4);
    
    #if VERBOSE_MAINLOOP_CHATTER
    fprintf(log_file, "%d, %f, %f\n", iter, lastKnownAX, lastKnownAX);
    #endif
    iter++;
    /* Sanity check orientation info, reset if stupid */
    if (fabs(lastKnownAX) > 10000)   lastKnownAX = 0;
    if (fabs(lastKnownAY) > 10000)   lastKnownAY = 0;

    /* Assembly message in order N S E W */
    
    /* z-level */
    floats[0] = fabs(q_z_tran);
    floats[1] = fabs(q_z_tran);
    floats[2] = fabs(q_z_tran);
    floats[3] = fabs(q_z_tran);

    /* Rotation around arms */ 
    floats[0] += q_y_spin + lastKnownAY/70.;
    floats[1] += -q_y_spin - lastKnownAY/70.;
    floats[2] += q_x_spin + lastKnownAX/70.;
    floats[3] += -q_x_spin - lastKnownAX/70.;
    /* Yaw */
    floats[0] += q_z_spin;
    floats[1] += q_z_spin;
    floats[2] -= q_z_spin;
    floats[3] -= q_z_spin;

    for (i=0; i<4; i++){
      if (floats[i]<0) floats[i] = 0;
      else if (floats[i] > 1) floats[i] = 1;
    }

    msg.data = floats;
    /* Send off message */
    chatter_pub.publish(msg);


    /* Wait out till next loop */
    ros::spinOnce();
    loop_rate.sleep();
  }
  fclose(log_file);

  return 0;
}
コード例 #15
0
int LuaGenerator::parameter(lua_State *L, int index)
{
    const char *typedname = luaL_checkstring(L, index);

    core::ParamType type;
    if (type.fromstring(typedname, NULL) == false)
        return luaL_error(L, "TypeError: Cannot parse parameter type.");

    bool istable = lua_istable(L, index + 1);

    int totalElements = type.type.numelements() * type.type.aggregate;

    if (totalElements > 1 && !istable)
        return luaL_error(L, "TypeError: Cannot pass single value to an array/vector/matrix type.");

    switch (type.type.basetype)
    {
    case OIIO::TypeDesc::FLOAT:
    {
        if (istable)
        {
            int n = luaL_getn(L, index + 1);
            std::vector<float> floats(n);
            for (int i = 0; i < n; ++i)
            {
                lua_rawgeti(L, index + 1, i + 1);
                floats[i] = luaL_checknumber(L, -1);
                lua_pop(L, 1);
            }
            api_->parameter(typedname, tokenize(floats));
        }
        else
        {
            api_->parameter(typedname, luaL_checknumber(L, index + 1));
        }
        break;
    }
    case OIIO::TypeDesc::INT:
    {
        if (istable)
        {
            int n = luaL_getn(L, index + 1);
            std::vector<int> ints(n);
            for (int i = 0; i < n; ++i)
            {
                lua_rawgeti(L, index + 1, i + 1);
                ints[i] = luaL_checkint(L, -1);
                lua_pop(L, 1);
            }
            api_->parameter(typedname, tokenize(ints));
        }
        else
        {
            api_->parameter(typedname, luaL_checkint(L, index + 1));
        }
        break;
    }
    case OIIO::TypeDesc::STRING:
    {
        if (istable)
        {
            int n = luaL_getn(L, index + 1);
            std::vector<const char*> strs(n);
            for (int i = 0; i < n; ++i)
            {
                lua_rawgeti(L, index + 1, i + 1);
                strs[i] = luaL_checkstring(L, -1);
                lua_pop(L, 1);
            }
            api_->parameter(typedname, tokenize(strs));
        }
        else
        {
            api_->parameter(typedname, tokenize(luaL_checkstring(L, index + 1)));
        }
        break;
    }
    default:
        return luaL_error(L, "TypeError: Unsupported base type.");
    }

    return 0;
}
コード例 #16
0
    "Floatarray in Luxinia for array operations.",NULL,LUX_TRUE);
  FunctionPublish_setParent(LUXI_CLASS_FLOATARRAY,LUXI_CLASS_STATICARRAY);
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticArray_new,(void*)LUXI_CLASS_FLOATARRAY,"new",
    "(floatarray):(int count) - creates a new staticarray. Count must be >0.");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,(void*)VA_OPLIT,"v4lit",
    "():(floatarray outputintensities(4n), floatarray vertexpos(3n), floatarray vertexnormal(3n), float lightpos x,y,z ,float diffuse r,g,b ,float ambient r,g,b ,float attconst, float attlin, float attsq) - \
computes per vertex lighting intensities for n vertices into the given array. The given light position, attenuation and color values are used. Note that light position must be in same coordinate system as vertices (local).");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,(void*)VA_SPLINE3,"v3spline",
    "():(floatarray interpolated(3i), floatarray splinepos(3n),[int noverride]) - \
does spline interpolation based on the n splinepos vectors (eventimed), and interpolates using i steps.");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,(void*)VA_SPLINE4,"v4spline",
    "():(floatarray interpolated(4i), floatarray splinepos(4n),[int noverride]) - \
does spline interpolation based on the n splinepos vectors (eventimed), and interpolates using i steps.");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,(void*)VA_LERP,"lerp",
    "():(floatarray interpolated(i), floatarray splinepos(n),[int noverride]) - \
does linear interpolation based on the n floats (eventimed), and interpolates using i steps.");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,(void*)VA_LERP3,"v3lerp",
    "():(floatarray interpolated(3i), floatarray splinepos(3n),[int noverride]) - \
does linear interpolation based on the n vectors (eventimed), and interpolates using i steps.");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,(void*)VA_LERP4,"v4lerp",
    "():(floatarray interpolated(4i), floatarray splinepos(4n),[int noverride]) - \
does linear interpolation based on the n vectors (eventimed), and interpolates using i steps.");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,(void*)VA_TONEXT3,"v3tonext",
    "():(floatarray out(3n)) - for every vector we do (next-self)");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,
    (void*)VA_OPADD,"add","():(floatarray self,floatarray / value a, [floatarray b]) - self+=a or self = a + b");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,
    (void*)VA_OPSUB,"sub","():(floatarray self,floatarray / value a, [floatarray b]) - self-=a or self = a - b");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,
    (void*)VA_OPMUL,"mul","():(floatarray self,floatarray / value a, [floatarray b]) - self*=a or self = a * b");
  FunctionPublish_addFunction(LUXI_CLASS_FLOATARRAY,PubStaticFloatArray_prop_FPU,
コード例 #17
0
fastuidraw::gl::varying_list&
fastuidraw::gl::varying_list::
add_float_varying(const char *pname, enum interpolation_qualifier_t q)
{
  return set_float_varying(floats(q).size(), pname, q);
}