// Triangulate an unimonotone chain.
bool TriangulateMonotone(Vertex *first, Vertex *last,
                         SkTDArray<SkPoint> *triangles) {
    DebugPrintf("TriangulateMonotone()\n");

    size_t numVertices = CountVertices(first, last);
    if (numVertices == kMaxCount) {
        FailureMessage("Way too many vertices: %d:\n", numVertices);
        PrintLinkedVertices(numVertices, first);
        return false;
    }

    Vertex *start = first;
    // First find the point with the smallest Y.
    DebugPrintf("TriangulateMonotone: finding bottom\n");
    int count = kMaxCount;    // Maximum number of vertices.
    for (Vertex *v = first->next(); v != first && count-- > 0; v = v->next())
        if (v->point() < start->point())
            start = v;
    if (count <= 0) {
        FailureMessage("TriangulateMonotone() was given disjoint chain\n");
        return false;   // Something went wrong.
    }

    // Start at the far end of the long edge.
    if (start->prev()->point() < start->next()->point())
        start = start->next();

    Vertex *current = start->next();
    while (numVertices >= 3) {
        if (current->angleIsConvex()) {
            DebugPrintf("Angle %p is convex\n", current);
            // Print the vertices
            PrintLinkedVertices(numVertices, start);

            appendTriangleAtVertex(current, triangles);
            if (triangles->count() > kMaxCount * 3) {
                FailureMessage("An extraordinarily large number of triangles "
                               "were generated\n");
                return false;
            }
            Vertex *save = current->prev();
            current->delink();
            current = (save == start || save == start->prev()) ? start->next()
                                                               : save;
            --numVertices;
        } else {
            if (numVertices == 3) {
                FailureMessage("Convexity error in TriangulateMonotone()\n");
                appendTriangleAtVertex(current, triangles);
                return false;
            }
            DebugPrintf("Angle %p is concave\n", current);
            current = current->next();
        }
    }
    return true;
}
Example #2
0
File: tester.c Project: zanderdk/P1
int main(int argc, char const *argv[])
{
	FILE *fp = fopen("demo2.xml", "r");
	Floor *graph = readXml(fp);
	fclose(fp);

	Vertex *t = GetVertexFromId("10013", graph);

	printf("%d \n", CountVertices(1, graph));

	return 0;
}
Example #3
0
// -----------------------------------------------------------------------------------
// Implementation of the assimp info utility to print basic file info
int Assimp_Info (const char* const* params, unsigned int num)
{
	if (num < 1) {
		printf("assimp info: Invalid number of arguments. "
			"See \'assimp info --help\'\n");
		return 1;
	}

	// --help
	if (!strcmp( params[0],"-h")||!strcmp( params[0],"--help")||!strcmp( params[0],"-?") ) {
		printf("%s",AICMD_MSG_INFO_HELP_E);
		return 0;
	}

	// asssimp info <file> [-r]
	if (num < 1) {
		printf("assimp info: Invalid number of arguments. "
			"See \'assimp info --help\'\n");
		return 1;
	}

	const std::string in  = std::string(params[0]);

	// do maximum post-processing unless -r was specified
	ImportData import;
	import.ppFlags = num>1&&(!strcmp(params[1],"--raw")||!strcmp(params[1],"-r")) ? 0
		: aiProcessPreset_TargetRealtime_MaxQuality;

	// import the main model
    import.log = true;
    import.showLog = true;
	const aiScene* scene = ImportModel(import,in);
	if (!scene) {
		printf("assimp info: Unable to load input file %s\n",
			in.c_str());
		return 5;
	}

	aiMemoryInfo mem;
	globalImporter->GetMemoryRequirements(mem);


	static const char* format_string = 
		"Memory consumption: %i B\n"
		"Nodes:              %i\n"
		"Maximum depth       %i\n"
		"Meshes:             %i\n"
		"Animations:         %i\n"
		"Textures (embed.):  %i\n"
		"Materials:          %i\n"
		"Cameras:            %i\n"
		"Lights:             %i\n"
		"Vertices:           %i\n"
		"Faces:              %i\n"
		"Bones:              %i\n"
		"Animation Channels: %i\n"
		"Primitive Types:    %s\n"
		"Average faces/mesh  %i\n"
		"Average verts/mesh  %i\n"
		"Minimum point      (%f %f %f)\n"
		"Maximum point      (%f %f %f)\n"
		"Center point       (%f %f %f)\n"

		;

	aiVector3D special_points[3];
	FindSpecialPoints(scene,special_points);
	printf(format_string,
		mem.total,
		CountNodes(scene->mRootNode),
		GetMaxDepth(scene->mRootNode),
		scene->mNumMeshes,
		scene->mNumAnimations,
		scene->mNumTextures,
		scene->mNumMaterials,
		scene->mNumCameras,
		scene->mNumLights,
		CountVertices(scene),
		CountFaces(scene),
		CountBones(scene),
		CountAnimChannels(scene),
		FindPTypes(scene).c_str(),
		GetAvgFacePerMesh(scene),
		GetAvgVertsPerMesh(scene),
		special_points[0][0],special_points[0][1],special_points[0][2],
		special_points[1][0],special_points[1][1],special_points[1][2],
		special_points[2][0],special_points[2][1],special_points[2][2]
		)
	;
	unsigned int total=0;
	for(unsigned int i = 0;i < scene->mNumMaterials; ++i) {
		aiString name;
		if (AI_SUCCESS==aiGetMaterialString(scene->mMaterials[i],AI_MATKEY_NAME,&name)) {
			printf("%s\n    \'%s\'",(total++?"":"\nNamed Materials:" ),name.data);
		}
	}
	if(total) {
		printf("\n");
	}

	total=0;
	for(unsigned int i = 0;i < scene->mNumMaterials; ++i) {
		aiString name;
		static const aiTextureType types[] = {
			aiTextureType_NONE,
			aiTextureType_DIFFUSE,
			aiTextureType_SPECULAR,
			aiTextureType_AMBIENT,
			aiTextureType_EMISSIVE,
			aiTextureType_HEIGHT,
			aiTextureType_NORMALS,
			aiTextureType_SHININESS,
			aiTextureType_OPACITY,
			aiTextureType_DISPLACEMENT,
			aiTextureType_LIGHTMAP,
			aiTextureType_REFLECTION,
			aiTextureType_UNKNOWN
		};
		for(unsigned int type = 0; type < sizeof(types)/sizeof(types[0]); ++type) {
			for(unsigned int idx = 0;AI_SUCCESS==aiGetMaterialString(scene->mMaterials[i],
				AI_MATKEY_TEXTURE(types[type],idx),&name); ++idx) {
				printf("%s\n    \'%s\'",(total++?"":"\nTexture Refs:" ),name.data);
			}
		}
	}
	if(total) {
		printf("\n");
	}

	total=0;
	for(unsigned int i = 0;i < scene->mNumAnimations; ++i) {
		if (scene->mAnimations[i]->mName.length) {
			printf("%s\n     \'%s\'",(total++?"":"\nNamed Animations:" ),scene->mAnimations[i]->mName.data);
		}
	}
	if(total) {
		printf("\n");
	}

	printf("\nNode hierarchy:\n");
	unsigned int cline=0;
	PrintHierarchy(scene->mRootNode,20,1000,cline);

	printf("\n");
	return 0;
}
Example #4
0
// -----------------------------------------------------------------------------------
unsigned int GetAvgVertsPerMesh(const aiScene* scene) {
	if (scene->mNumMeshes != 0)
		return static_cast<unsigned int>(CountVertices(scene)/scene->mNumMeshes);
}
Example #5
0
// -----------------------------------------------------------------------------------
// Implementation of the assimp info utility to print basic file info
int Assimp_Info(const aiScene* scene, Assimp::Importer *globalImporter)
{


    aiMemoryInfo mem;
    globalImporter->GetMemoryRequirements(mem);


    static const char* format_string =
        "Memory consumption: %i B\n"
        "Nodes:              %i\n"
        "Maximum depth       %i\n"
        "Meshes:             %i\n"
        "Animations:         %i\n"
        "Textures (embed.):  %i\n"
        "Materials:          %i\n"
        "Cameras:            %i\n"
        "Lights:             %i\n"
        "Vertices:           %i\n"
        "Faces:              %i\n"
        "Bones:              %i\n"
        "Animation Channels: %i\n"
        "Primitive Types:    %s\n"
        "Average faces/mesh  %i\n"
        "Average verts/mesh  %i\n"
        "Minimum point      (%f %f %f)\n"
        "Maximum point      (%f %f %f)\n"
        "Center point       (%f %f %f)\n"

        ;

    aiVector3D special_points[3];
    FindSpecialPoints(scene, special_points);
    fprintf(stderr, format_string,
            mem.total,
            CountNodes(scene->mRootNode),
            GetMaxDepth(scene->mRootNode),
            scene->mNumMeshes,
            scene->mNumAnimations,
            scene->mNumTextures,
            scene->mNumMaterials,
            scene->mNumCameras,
            scene->mNumLights,
            CountVertices(scene),
            CountFaces(scene),
            CountBones(scene),
            CountAnimChannels(scene),
            FindPTypes(scene).c_str(),
            GetAvgFacePerMesh(scene),
            GetAvgVertsPerMesh(scene),
            special_points[0][0], special_points[0][1], special_points[0][2],
            special_points[1][0], special_points[1][1], special_points[1][2],
            special_points[2][0], special_points[2][1], special_points[2][2]
           )
    ;
#define FULLLOG
#ifdef FULLLOG
    unsigned int total = 0;
    for (unsigned int i = 0; i < scene->mNumMaterials; ++i) {
        aiString name;
        if (AI_SUCCESS == aiGetMaterialString(scene->mMaterials[i], AI_MATKEY_NAME, &name)) {
            fprintf(stderr, "%s\n    \'%s\'", (total++ ? "" : "\nNamed Materials:"), name.data);
        }
    }
    if (total) {
        fprintf(stderr, "\n");
    }

    total = 0;
    for (unsigned int i = 0; i < scene->mNumMaterials; ++i) {
        aiString name;
        static const aiTextureType types[] = {
            aiTextureType_NONE,
            aiTextureType_DIFFUSE,
            aiTextureType_SPECULAR,
            aiTextureType_AMBIENT,
            aiTextureType_EMISSIVE,
            aiTextureType_HEIGHT,
            aiTextureType_NORMALS,
            aiTextureType_SHININESS,
            aiTextureType_OPACITY,
            aiTextureType_DISPLACEMENT,
            aiTextureType_LIGHTMAP,
            aiTextureType_REFLECTION,
            aiTextureType_UNKNOWN
        };
        for (unsigned int type = 0; type < sizeof(types) / sizeof(types[0]); ++type) {
            for (unsigned int idx = 0; AI_SUCCESS == aiGetMaterialString(scene->mMaterials[i],
                    AI_MATKEY_TEXTURE(types[type], idx), &name); ++idx) {
                fprintf(stderr, "%s\n    \'%s\'", (total++ ? "" : "\nTexture Refs:"), name.data);
            }
        }
    }
    if (total) {
        fprintf(stderr, "\n");
    }

    total = 0;
    for (unsigned int i = 0; i < scene->mNumAnimations; ++i) {
        if (scene->mAnimations[i]->mName.length) {
            fprintf(stderr, "%s\n     \'%s\'", (total++ ? "" : "\nNamed Animations:"), scene->mAnimations[i]->mName.data);
        }
    }
    if (total) {
        fprintf(stderr, "\n");
    }

 /*
   fprintf(stderr, "\nNode hierarchy:\n");
    unsigned int cline = 0;
    PrintHierarchy(scene->mRootNode, 20, 1000, cline);
    */
#endif
    fprintf(stderr, "\n");
    return 0;
}