Example #1
0
void testApp::save() {
    ofxXmlSettings xml;
    
    xml.addTag("city");
    xml.pushTag("city");
    
    for (vector<screen>::iterator siter=screens.begin(); siter!=screens.end(); siter++) {
        xml.addTag("screen");
        xml.addAttribute("screen", "index", siter->index,0);
        xml.pushTag("screen",distance(screens.begin(), siter));
        
        for (vector<int>::iterator iter=siter->indices.begin();iter!=siter->indices.end();iter++) {
            xml.addTag("index");
            xml.addAttribute("index", "value", *iter,distance(siter->indices.begin(), iter));
        }
        
        writeVertex(xml, siter->origin,0);
        writeVertex(xml, siter->xVec,1);
        writeVertex(xml, siter->yVec,2);
        
        
        xml.popTag();
    }
    
    for (vector<tent >::iterator titer=tents.begin(); titer!=tents.end(); titer++) {
        xml.addTag("tent");
        xml.addAttribute("tent", "first", titer->first,distance(tents.begin(), titer));
        xml.addAttribute("tent", "second", titer->second,distance(tents.begin(), titer));
    }
    
    for (vector<ofRectangle>::iterator riter=rects.begin();riter!=rects.end();riter++) {
        xml.addTag("rect");
        xml.addAttribute("rect", "x", riter->x,distance(rects.begin(), riter));
        xml.addAttribute("rect", "y", riter->y,distance(rects.begin(), riter));
        xml.addAttribute("rect", "w", riter->width,distance(rects.begin(), riter));
        xml.addAttribute("rect", "h", riter->height,distance(rects.begin(), riter));
    }
    
    xml.popTag();
    
    xml.saveFile("settings.xml");
    
    updateMatices();
    
}
Example #2
0
void writeGraphviz(std::ostream& out, const NFA& graph) {
  out << "digraph G {\n  rankdir=LR;\n  ranksep=equally;\n  node [shape=\"circle\"];" << std::endl;

  for (const NFA::VertexDescriptor v : graph.vertices()) {
    writeVertex(out, v, graph);
  }

  for (const NFA::VertexDescriptor head : graph.vertices()) {
    for (uint32_t j = 0; j < graph.outDegree(head); ++j) {
      writeEdge(out, head, graph.outVertex(head, j), j, graph);
    }
  }

  out << "}" << std::endl;
}
Example #3
0
void D3MFExporter::writeMesh( aiMesh *mesh ) {
    if ( nullptr == mesh ) {
        return;
    }

    mModelOutput << "<" << XmlTag::mesh << ">" << std::endl;
    mModelOutput << "<" << XmlTag::vertices << ">" << std::endl;
    for ( unsigned int i = 0; i < mesh->mNumVertices; ++i ) {
        writeVertex( mesh->mVertices[ i ] );
    }
    mModelOutput << "</" << XmlTag::vertices << ">" << std::endl;

    writeFaces( mesh );

    mModelOutput << "</" << XmlTag::mesh << ">" << std::endl;
}
Example #4
0
int writeEdges(FILE *file, const short *edges, const unsigned char *edge_colors)
{
	int vertexCount = 0;
	const short *edge = edges + scan_camera->height;
	const unsigned char *edgecol = edge_colors;
	float div = 1.0f / (float)scan_camera->height;
	for(int i = 0; i < STEPS; i++)
	{
		float angle = (float)i / (float)STEPS * 2.0f * 3.14159f;
		float c = div * 1.5f * cosf(angle);
		float s = div * 1.5f * sinf(angle);

		const unsigned char *rgb = edgecol;
		for(int y = 1; y < scan_camera->height - 1; y++)
		{
			if (edge[y] != NOEDGE)
			{
				float px = c * edge[y];
				float py = s * edge[y];
				float pz = div * (float)(scan_camera->height - y - 1);

				/*float nx = ;
				float ny = ;
				float nz = ;
				unsigned char r = edge_colors ? rgb[0] : 255;
				unsigned char g = edge_colors ? rgb[1] : 255;
				unsigned char b = edge_colors ? rgb[2] : 255;*/

				writeVertex(file, px, py, pz/*, -nx, -ny, -nz, r, g, b*/);
				vertexCount++;
			}
			rgb += 4;
		}
		edge += scan_camera->height;
		edgecol += scan_camera->height * 4;
	}
	return vertexCount;
}
Example #5
0
void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color,
                                  double width, bool polygon )
{
  writeGroup( 0, "POLYLINE" );
  writeGroup( 8, layer );
  writeGroup( 6, lineStyleName );
  writeGroup( 62, color );
  writeGroup( 66, 1 );
  int type = polygon ? 1 : 0;
  writeGroup( 70, type );
  if ( width > 0 ) //width -1: use default width
  {
    writeGroup( 40, width );
    writeGroup( 41, width );
  }

  QgsPolyline::const_iterator lineIt = line.constBegin();
  for ( ; lineIt != line.constEnd(); ++lineIt )
  {
    writeVertex( *lineIt, layer );
  }

  writeGroup( 0, "SEQEND" );
}
Example #6
0
void AtlasOldMesher::write(Stream *s, const S8 level, bool doWriteCollision)
{
   AssertISV(mIndices.size(), "AtlasOldMesher::write - no indices to write?!?");

   // First, figure our bounds.
   updateBounds();

   // Then, run the tristripper, get our geometry a bit more optimal.
   ///optimize();

   // We start at the appropriate position in the TOC. It's great!

   // Write min & max y values.  This can be used to reconstruct
   // the bounding box.
   s->write(mMinZ);
   s->write(mMaxZ);

   // Write a placeholder for the mesh data file pos.
   U32 currentPos = s->getPosition();
   s->write(U32(0));

   // write out the vertex data at the *end* of the file.
   s->setPosition(s->getStreamSize());
   U32 meshPos = s->getPosition();

   // Write a sentinel.
   s->write(U32(0xbeef1234));

   // Make sure the vertex buffer is not too big.
   if(mVerts.size() > 0xFFFF)
   {
      AssertISV(false,
         "AtlasOldMesher::write - too many vertices! (> 65535) Try making a deeper tree!");
   }

   // Write vertices.  All verts contain morph info.
   s->write(U16(mVerts.size()));
   for (int i = 0; i < mVerts.size(); i++)
      writeVertex(s, &mVerts[i], level);

   // Write the index buffer.
   s->write(S32(mIndices.size()));
   for(S32 i=0; i<mIndices.size(); i++)
      s->write(mIndices[i]);

   // Write the triangle count.
   s->write(U32(mIndices.size()) / 3);

   gOldChunkGenStats.outputRealTriangles += mIndices.size() / 3;

   // Now, we have to make our collision info...
   if(doWriteCollision)
   {
      s->write(U8(1));
      writeCollision(s);
   }
   else
   {
      s->write(U8(0));
   }

   // write the postscript.
   s->write(U32(0xb1e2e3f4));

   // Rewind, and fill in the mesh data file pos.
   s->setPosition(currentPos);
   s->write(meshPos);

   // Con::printf("    - %d indices, %d verts, meshOffset=%d", mIndices.size(), mVerts.size(), meshPos);
}
Example #7
0
/******************************************
* Writes a given object to a displaylist  *
******************************************/
void writeDL(char *filename, object *obj, int vertex_cache_size, int one_triangle)
{
    FILE *fp;
    int i;
    int j;
    int k;
    int v;
    int n;
    char objname[64];
    
    char *verts;
    
    material  *matp;
    mesh    *meshp;
    face    *facep;
    vertex  *vertp;
    point2  *texcp;
    point3  *normp;
    texture *texp;
    
    int total_face = 0;
    
    int current_mesh = 0;
    int current_mat = 0;
    int current_vertex = 0;
    int current_normal = 0;
    int current_texcoord = 0;
    int current_face = 0;
    int current_texture = 0;
    
    
    
    
    
    // vertex building
    char temp[256];
    char *dl;
    char *tris;
    char a,b,c,d,e,f;
    a=b=c=d=e=f=0;
    int vert_list_count;
    // texture optimization
    int matindex[256]; // assume 256 max textures
    //char meshnames[256][100];  // 256 max meshes
    
    mesh *meshptrs[256];
    
    
    
    
    fp = fopen(filename, "w");
    if(fp == NULL){
        printf("Failed to open file %s for writing\n", filename);
        exit(1);
    }
    
    strncpy(objname, filename, strlen(filename)-2);
    objname[ strlen(filename)-2 ] = 0;
    
    fprintf(fp, "//\n");
    fprintf(fp, "// Displaylist generated by OBJN64 \n");
    fprintf(fp, "// Input: %s\n", filename);
    fprintf(fp, "//\n");
    fprintf(fp, "\n");
    
    // go through each texture
    for(current_texture = 0; current_texture < obj->numTextures; current_texture++)
    {
       
        texp = &obj->textures[current_texture];
    
        // what kind of texture format???
        if(texp->mode == TEX_MODE_RGBA_5551)
        {
            fprintf(fp, "unsigned short Text_%s_%s_diff[] = {\n", objname, texp->name);
            
            i = 0;
            for(j = 0; j < texp->w * texp->h; j++)
            {
                fprintf(fp, "0x%04x, ", texp->data[j]);
                i++;
                if(i == 13) {fprintf(fp, "\n"); i = 0;}
            }
            
            fprintf(fp, "}; \n\n");
        }
    }

    // go through each mesh
    for(current_mesh = 0; current_mesh < obj->numMeshes; current_mesh++)
    {
      meshp = &obj->meshes[current_mesh];
      matp = &obj->materials[meshp->material_num];
      dl = NULL;
      if(strstr(meshp->name, "_aoh") == NULL)
      {
        
        // triangle and vertex loading    
        sprintf(temp, "Gfx Vtx_%s_%s_dl[] = {\n", objname, meshp->name);
        dl = strdup(temp);
        
        current_face = 0;
        vert_list_count = 0;
        verts_pos = 0;
        tris = NULL;
        while(current_face < meshp->numFaces)
        {
            facep = &meshp->faces[current_face];
            
            // get points. interpPoint() will add the point if it is not there
            writeVertex(temp, obj, matp, &meshp->vertices[facep->v[0]-1]);
            a = interpPoint( temp );
            writeVertex(temp, obj, matp, &meshp->vertices[facep->v[1]-1]);
            b = interpPoint( temp );
            writeVertex(temp, obj, matp, &meshp->vertices[facep->v[2]-1]);
            c = interpPoint( temp );
            
            //vertex buffer full / on last triangle in mesh?
            //if(verts_pos > 29 || current_face+1 == meshp->numFaces)
            if(verts_pos > vertex_cache_size-3|| current_face+1 == meshp->numFaces)
            {            /* ^--potential optimization: if (verts_pos-29 < 3) , see
                           if adding one or two more verts completes another triangle */
                //append to vertex buff (write to fp)
                fprintf(fp, "Vtx_tn Vtx_%s_%s_%i[%i] = {\n", objname, meshp->name, vert_list_count, verts_pos);
                for (n = 0; n < verts_pos; n++)
                    fprintf(fp, "%s", tmp_verts[n]);
                fprintf(fp, "};\n\n" );
                //append to display list (add to string)
                sprintf(temp, "\tgsSPVertex(&Vtx_%s_%s_%i[0], %i, 0),\n", objname, meshp->name, vert_list_count, verts_pos);
                dl = strcatdup(dl, temp);
                dl = strcatdup(dl, tris);
                if (!d && !e && !f){
                    sprintf(temp, "\tgsSP1Triangle(%i, %i, %i, 0),\n", a, b, c);
                }else{
                    if(one_triangle){
						sprintf(temp, "\tgsSP1Triangle(%i, %i, %i, 0),\n", d, e, f);
						sprintf(temp, "\tgsSP1Triangle(%i, %i, %i, 0),\n", a, b, c);
					}else{
		                sprintf(temp, "\tgsSP2Triangles(%i, %i, %i, 0, %i, %i, %i, 0),\n", d, e, f, a, b, c);
					}
				}
				
                dl = strcatdup(dl, temp);
                //reset vars
                d=e=f=0;
                tris = NULL;
                vert_list_count++;
                verts_pos=0;
            }
            //second set of points set?
            else if (d|e|f)
            { // Yes - do a triangle, reset them.
            	if(one_triangle){
					sprintf(temp, "\tgsSP1Triangle(%i, %i, %i, 0),\n", d, e, f);
					sprintf(temp, "\tgsSP1Triangle(%i, %i, %i, 0),\n", a, b, c);
				}else{
	                sprintf(temp, "\tgsSP2Triangles(%i, %i, %i, 0, %i, %i, %i, 0),\n", d, e, f, a, b, c);
				}
                tris = strcatdup(tris, temp);
                d=e=f=0;
            }
            else
            { // No - set them.
                d = a;
                e = b;
                f = c;
            }
            
            total_face++;
            current_face++;
        }
        
        
        fprintf(fp, "%s", dl);
        fprintf(fp,"\tgsSPEndDisplayList(),\n");
        fprintf(fp, "};\n\n");
        
        if(tris != NULL) free(tris);
        if(dl != NULL) free(dl);
        tris = dl = NULL;
      }
    }
    
    // go through each mesh
    // apply materials/textures
    fprintf(fp, "Gfx Wtx_%s[] = {\n", objname);
    
    
    // set up material look-up
    for(current_mesh = 0; current_mesh < obj->numMeshes; current_mesh++)
    {
        meshp = &obj->meshes[current_mesh];
        
        // copy meshname to holding array
        //strcpy(meshnames[current_mesh], meshp->name);
        meshptrs[current_mesh] = meshp;
        matindex[current_mesh] = meshp->material_num;
        
        
        //printf("    %s,  %d\n", meshnames[current_mesh], matindex[current_mesh]);
    }
    
    // now sort the materials and all their objects
    for(i = 0; i < obj->numMeshes; i++)
    {
        for(j = 0; j < obj->numMeshes-1; j++)
        {
            if(matindex[j] > matindex[j+1])
            {
                // swap
                k = matindex[j] ;
                matindex[j] = matindex[j+1];
                matindex[j+1] = k;
                
                meshp = meshptrs[j];
                meshptrs[j] = meshptrs[j+1];
                meshptrs[j+1] = meshp;
            }
        }        
    } 
       
    current_mat = -1;
    for(current_mesh = 0; current_mesh < obj->numMeshes; current_mesh++)
    {
        //meshp = &obj->meshes[current_mesh];
        
        if(strstr(meshptrs[current_mesh]->name, "_aoh") == NULL){
            
        // check if the material has changed
        if(matindex[current_mesh] != current_mat){
            current_mat = matindex[current_mesh];
            matp = &obj->materials[current_mat];
            
            fprintf(fp, "\tgsDPLoadTextureBlock(Text_%s_%s_diff, G_IM_FMT_RGBA, G_IM_SIZ_16b, \n\t\t%d,%d, 0, G_TX_WRAP|G_TX_NOMIRROR, G_TX_WRAP|G_TX_NOMIRROR,\n\t\t%d,%d, G_TX_NOLOD, G_TX_NOLOD),\n", 
            objname, 
            
            obj->textures[matp->texture_num].name, 
            obj->textures[matp->texture_num].w, 
            obj->textures[matp->texture_num].h,
            
            (int)lroundf(log((float)obj->textures[matp->texture_num].w) / log(2.0f)),
            (int)lroundf(log((float)obj->textures[matp->texture_num].h) / log(2.0f))
            
            );
        }
        
        
        
        
        
        fprintf(fp, "\tgsSPDisplayList(Vtx_%s_%s_dl),\n", objname, meshptrs[current_mesh]->name); //meshp->name);
        
        }
    }
    fprintf(fp,"\tgsSPEndDisplayList(),\n");
    fprintf(fp, "};\n\n");
    
    printf("Finished writing displaylist\n");
    printf("Total triangles: %d\n", total_face);
    
    fclose(fp);
}