diff options
author | Karl Berry <karl@freefriends.org> | 2011-05-28 02:18:52 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2011-05-28 02:18:52 +0000 |
commit | c59fe5fe4739f0c61560f05d4e42b4e552219b27 (patch) | |
tree | 8cf79e85e394b3177a28d374415840a4e0a025ad /Build/source/utils/asymptote/prc | |
parent | 771db15706dbf3f4af8b630dcb15646a3e5fda00 (diff) |
asy 2.10
git-svn-id: svn://tug.org/texlive/trunk@22633 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/prc')
-rw-r--r-- | Build/source/utils/asymptote/prc/Makefile | 8 | ||||
-rw-r--r-- | Build/source/utils/asymptote/prc/PRC.h | 13 | ||||
-rw-r--r-- | Build/source/utils/asymptote/prc/PRCbitStream.cc | 13 | ||||
-rw-r--r-- | Build/source/utils/asymptote/prc/PRCbitStream.h | 16 | ||||
-rw-r--r-- | Build/source/utils/asymptote/prc/oPRCFile.cc | 1119 | ||||
-rw-r--r-- | Build/source/utils/asymptote/prc/oPRCFile.h | 408 | ||||
-rw-r--r-- | Build/source/utils/asymptote/prc/test.cc | 816 | ||||
-rw-r--r-- | Build/source/utils/asymptote/prc/writePRC.cc | 81 | ||||
-rw-r--r-- | Build/source/utils/asymptote/prc/writePRC.h | 52 |
9 files changed, 1642 insertions, 884 deletions
diff --git a/Build/source/utils/asymptote/prc/Makefile b/Build/source/utils/asymptote/prc/Makefile index 22f67e29725..af1a50084dd 100644 --- a/Build/source/utils/asymptote/prc/Makefile +++ b/Build/source/utils/asymptote/prc/Makefile @@ -10,6 +10,12 @@ FILES = PRCbitStream oPRCFile PRCdouble writePRC test: $(FILES:=.o) test.cc $(CXX) $(CFLAGS) -o test $(FILES:=.o) test.cc -lz +test_tess: $(FILES:=.o) test_tess.cc + $(CXX) $(CFLAGS) -o test_tess $(FILES:=.o) test_tess.cc -lz + +test_mesh: $(FILES:=.o) test_mesh.cc + $(CXX) $(CFLAGS) -o test_mesh $(FILES:=.o) test_mesh.cc -lz + .SUFFIXES: .c .cc .o .d .cc.o: $(CXX) $(CFLAGS) $(INCL) -o $@ -c $< @@ -31,4 +37,4 @@ ifeq (,$(findstring clean,${MAKECMDGOALS})) endif clean: - rm -f *.o *.d test.prc test + rm -f *.o *.d test test_tess diff --git a/Build/source/utils/asymptote/prc/PRC.h b/Build/source/utils/asymptote/prc/PRC.h index 8acaa453ca3..9ce6ea70e0e 100644 --- a/Build/source/utils/asymptote/prc/PRC.h +++ b/Build/source/utils/asymptote/prc/PRC.h @@ -1,7 +1,20 @@ #ifndef __PRC_H #define __PRC_H +#ifdef _MSC_VER +#if _MSC_VER >= 1600 +#include <stdint.h> +#else +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed long int32_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; +#endif // _MSC_VER >= 1600 +#else #include <inttypes.h> +#endif // _MSC_VER //const uint32_t PRCVersion=7094; // For Adobe Reader 8 or later const uint32_t PRCVersion=8137; // For Adobe Reader 9 or later diff --git a/Build/source/utils/asymptote/prc/PRCbitStream.cc b/Build/source/utils/asymptote/prc/PRCbitStream.cc index 6ee4d8b45e7..bb013dcefe9 100644 --- a/Build/source/utils/asymptote/prc/PRCbitStream.cc +++ b/Build/source/utils/asymptote/prc/PRCbitStream.cc @@ -81,6 +81,19 @@ void PRCbitStream::compress() deflateEnd(&strm); } +void PRCbitStream::write(std::ostream &out) const +{ + if(compressed) + { + out.write((char*)data,compressedDataSize); + } + else + { + cerr << "Attempt to write stream before compression." << endl; + exit(1); + } +} + unsigned int PRCbitStream::getSize() const { if(compressed) diff --git a/Build/source/utils/asymptote/prc/PRCbitStream.h b/Build/source/utils/asymptote/prc/PRCbitStream.h index 89482168f9e..67142586e50 100644 --- a/Build/source/utils/asymptote/prc/PRCbitStream.h +++ b/Build/source/utils/asymptote/prc/PRCbitStream.h @@ -21,8 +21,23 @@ #ifndef __PRC_BIT_STREAM_H #define __PRC_BIT_STREAM_H +#ifdef _MSC_VER +#include <stdio.h> +#if _MSC_VER >= 1600 +#include <stdint.h> +#else +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed long int32_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; +#endif // _MSC_VER >= 1600 +#else #include <inttypes.h> +#endif // _MSC_VER #include <string> +#include <iostream> #include <stdlib.h> #define CHUNK_SIZE (1024) @@ -52,6 +67,7 @@ class PRCbitStream PRCbitStream& operator <<(const char*); void compress(); + void write(std::ostream &out) const; private: void writeBit(bool); void writeBits(uint32_t,uint8_t); diff --git a/Build/source/utils/asymptote/prc/oPRCFile.cc b/Build/source/utils/asymptote/prc/oPRCFile.cc index bef8191d703..cc4c302209f 100644 --- a/Build/source/utils/asymptote/prc/oPRCFile.cc +++ b/Build/source/utils/asymptote/prc/oPRCFile.cc @@ -30,6 +30,12 @@ #define WriteUnsignedInteger( value ) out << (uint32_t)(value); #define WriteInteger( value ) out << (int32_t)(value); +#define WriteDouble( value ) out << (double)(value); +#define WriteString( value ) out << (value); +#define WriteUncompressedUnsignedInteger( value ) writeUncompressedUnsignedInteger(out, (uint32_t)(value)); +#define WriteUncompressedBlock( value, count ) out.write((char *)(value),(count)); +#define SerializeFileStructureUncompressedUniqueId( value ) (value).serializeFileStructureUncompressedUniqueId(out); +#define SerializeCompressedUniqueId( value ) (value).serializeCompressedUniqueId(out); #define SerializeContentPRCBase write(out); #define SerializeRgbColor( value ) (value).serializeRgbColor(out); #define SerializePicture( value ) (value).serializePicture(out); @@ -39,46 +45,51 @@ #define SerializeFontKeysSameFont( value ) (value).serializeFontKeysSameFont(out); #define SerializeMaterial( value ) (value)->serializeMaterial(out); +#define SerializeUserData UserData(0,0).write(out); +#define SerializeEmptyContentPRCBase EMPTY_CONTENTPRCBASE.serializeContentPRCBase(out); #define SerializeCategory1LineStyle( value ) (value)->serializeCategory1LineStyle(out); #define SerializeCoordinateSystem( value ) (value)->serializeCoordinateSystem(out); #define SerializeRepresentationItem( value ) (value)->serializeRepresentationItem(out); #define SerializePartDefinition( value ) (value)->serializePartDefinition(out); #define SerializeProductOccurrence( value ) (value)->serializeProductOccurrence(out); -#define SerializeContextAndBodies( value ) (fileStructure->value)->serializeContextAndBodies(out); -#define SerializeGeometrySummary( value ) (fileStructure->value)->serializeGeometrySummary(out); -#define SerializeContextGraphics( value ) (fileStructure->value)->serializeContextGraphics(out); +#define SerializeContextAndBodies( value ) (value)->serializeContextAndBodies(out); +#define SerializeGeometrySummary( value ) (value)->serializeGeometrySummary(out); +#define SerializeContextGraphics( value ) (value)->serializeContextGraphics(out); +#define SerializeStartHeader serializeStartHeader(out); +#define SerializeUncompressedFiles \ + { \ + const uint32_t number_of_uncompressed_files = uncompressed_files.size(); \ + WriteUncompressedUnsignedInteger (number_of_uncompressed_files) \ + for(PRCUncompressedFileList::const_iterator it = uncompressed_files.begin(); it != uncompressed_files.end(); it++) \ + { \ + WriteUncompressedUnsignedInteger ((*it)->file_size) \ + WriteUncompressedBlock ((*it)->data, (*it)->file_size) \ + } \ + } +#define SerializeModelFileData serializeModelFileData(modelFile_out); modelFile_out.compress(); +#define SerializeUnit( value ) (value).serializeUnit(out); using std::string; using namespace std; -void PRCCompressedSection::write(ostream &out) +// Map [0,1] to [0,255] +inline uint8_t byte(double r) { - if(prepared) - out.write((char*)data,getSize()); + if(r < 0.0) r=0.0; + else if(r > 1.0) r=1.0; + int a=(int)(256.0*r); + if(a == 256) a=255; + return a; } -void PRCCompressedSection::prepare() -{ - writeData(); - compress(); - prepared = true; -} - -uint32_t PRCCompressedSection::getSize() -{ - if(!prepared) - return m1; - else - return out.getSize(); -} - -void PRCGlobalsSection::writeData() +void PRCFileStructure::serializeFileStructureGlobals(PRCbitStream &out) { // even though this is technically not part of this section, // it is handled here for convenience - out << (uint32_t)(0); // number of schemas - uint32_t i=0; // universal index for PRC standard compatibility - out << (uint32_t)PRC_TYPE_ASM_FileStructureGlobals; + const uint32_t number_of_schema = 0; + WriteUnsignedInteger (number_of_schema) + + WriteUnsignedInteger (PRC_TYPE_ASM_FileStructureGlobals) PRCSingleAttribute sa((int32_t)PRCVersion); PRCAttribute a("__PRC_RESERVED_ATTRIBUTE_PRCInternalVersion"); @@ -86,37 +97,39 @@ void PRCGlobalsSection::writeData() ContentPRCBase cb; cb.addAttribute(a); cb.serializeContentPRCBase(out); - out << numberOfReferencedFileStructures; // no referencing of file structures - out << tessellationChordHeightRatio; - out << tessellationAngleDegrees; - out << defaultFontFamilyName; // markup serialization helper + WriteUnsignedInteger (number_of_referenced_file_structures) + // SerializeFileStructureInternalGlobalData + WriteDouble (tessellation_chord_height_ratio) + WriteDouble (tessellation_angle_degree) + + // SerializeMarkupSerializationHelper + WriteString (default_font_family_name) const uint32_t number_of_fonts = font_keys_of_font.size(); WriteUnsignedInteger (number_of_fonts) - for (i=0;i<number_of_fonts;i++) + for (uint32_t i=0;i<number_of_fonts;i++) { SerializeFontKeysSameFont (font_keys_of_font[i]) } - const uint32_t number_of_colors = colors.size(); WriteUnsignedInteger (number_of_colors) - for (i=0;i<number_of_colors;i++) + for (uint32_t i=0;i<number_of_colors;i++) SerializeRgbColor (colors[i]) const uint32_t number_of_pictures = pictures.size(); WriteUnsignedInteger (number_of_pictures) - for (i=0;i<number_of_pictures;i++) + for (uint32_t i=0;i<number_of_pictures;i++) SerializePicture (pictures[i]) const uint32_t number_of_texture_definitions = texture_definitions.size(); WriteUnsignedInteger (number_of_texture_definitions) - for (i=0;i<number_of_texture_definitions;i++) + for (uint32_t i=0;i<number_of_texture_definitions;i++) SerializeTextureDefinition (texture_definitions[i]) const uint32_t number_of_materials = materials.size(); WriteUnsignedInteger (number_of_materials) - for (i=0;i<number_of_materials;i++) + for (uint32_t i=0;i<number_of_materials;i++) SerializeMaterial (materials[i]) out << (uint32_t)1 // number of line patterns hard coded for now @@ -128,95 +141,100 @@ void PRCGlobalsSection::writeData() const uint32_t number_of_styles = styles.size(); WriteUnsignedInteger (number_of_styles) - for (i=0;i<number_of_styles;i++) + for (uint32_t i=0;i<number_of_styles;i++) SerializeCategory1LineStyle (styles[i]) - out << numberOfFillPatterns; + const uint32_t number_of_fill_patterns = 0; + WriteUnsignedInteger (number_of_fill_patterns) const uint32_t number_of_reference_coordinate_systems = reference_coordinate_systems.size(); WriteUnsignedInteger (number_of_reference_coordinate_systems) - for (i=0;i<number_of_reference_coordinate_systems;i++) + for (uint32_t i=0;i<number_of_reference_coordinate_systems;i++) SerializeCoordinateSystem (reference_coordinate_systems[i]) - userData.write(out); + SerializeUserData } -void PRCTreeSection::writeData() +void PRCFileStructure::serializeFileStructureTree(PRCbitStream &out) { - out << (uint32_t)(PRC_TYPE_ASM_FileStructureTree); + WriteUnsignedInteger (PRC_TYPE_ASM_FileStructureTree) - EMPTY_CONTENTPRCBASE.serializeContentPRCBase(out); + SerializeEmptyContentPRCBase uint32_t number_of_part_definitions = part_definitions.size(); - WriteUnsignedInteger (number_of_part_definitions) + WriteUnsignedInteger (number_of_part_definitions) for (uint32_t i=0;i<number_of_part_definitions;i++) - SerializePartDefinition (part_definitions[i]) + SerializePartDefinition (part_definitions[i]) uint32_t number_of_product_occurrences = product_occurrences.size(); - WriteUnsignedInteger (number_of_product_occurrences) + WriteUnsignedInteger (number_of_product_occurrences) for (uint32_t i=0;i<number_of_product_occurrences;i++) { product_occurrences[i]->unit_information.unit_from_CAD_file = true; product_occurrences[i]->unit_information.unit = unit; - SerializeProductOccurrence (product_occurrences[i]) + SerializeProductOccurrence (product_occurrences[i]) } - // File Structure Internal Data - out << (uint32_t)(PRC_TYPE_ASM_FileStructure); - EMPTY_CONTENTPRCBASE.serializeContentPRCBase(out); - out << makePRCID(); // next available index - out << (uint32_t)1; // product occurrence index + // SerializeFileStructureInternalData + WriteUnsignedInteger (PRC_TYPE_ASM_FileStructure) + SerializeEmptyContentPRCBase + const uint32_t next_available_index = makePRCID(); + WriteUnsignedInteger (next_available_index) + const uint32_t index_product_occurence = number_of_product_occurrences; // Asymptote (oPRCFile) specific - we write the root product last + WriteUnsignedInteger (index_product_occurence) - UserData(0,0).write(out); + SerializeUserData } -void PRCTessellationSection::writeData() +void PRCFileStructure::serializeFileStructureTessellation(PRCbitStream &out) { - out << (uint32_t)(PRC_TYPE_ASM_FileStructureTessellation); + WriteUnsignedInteger (PRC_TYPE_ASM_FileStructureTessellation) - EMPTY_CONTENTPRCBASE.serializeContentPRCBase(out); + SerializeEmptyContentPRCBase const uint32_t number_of_tessellations = tessellations.size(); - WriteUnsignedInteger (number_of_tessellations) + WriteUnsignedInteger (number_of_tessellations) for (uint32_t i=0;i<number_of_tessellations;i++) tessellations[i]->serializeBaseTessData(out); - UserData(0,0).write(out); // no user data + + SerializeUserData } -void PRCGeometrySection::writeData() +void PRCFileStructure::serializeFileStructureGeometry(PRCbitStream &out) { - WriteUnsignedInteger (PRC_TYPE_ASM_FileStructureGeometry) + WriteUnsignedInteger (PRC_TYPE_ASM_FileStructureGeometry) - EMPTY_CONTENTPRCBASE.serializeContentPRCBase(out); - const uint32_t number_of_contexts = fileStructure->contexts.size(); - WriteUnsignedInteger (number_of_contexts) - for (uint32_t i=0;i<number_of_contexts;i++) - SerializeContextAndBodies (contexts[i]) + SerializeEmptyContentPRCBase + const uint32_t number_of_contexts = contexts.size(); + WriteUnsignedInteger (number_of_contexts) + for (uint32_t i=0;i<number_of_contexts;i++) + SerializeContextAndBodies (contexts[i]) - UserData(0,0).write(out); + SerializeUserData } -void PRCExtraGeometrySection::writeData() +void PRCFileStructure::serializeFileStructureExtraGeometry(PRCbitStream &out) { - WriteUnsignedInteger (PRC_TYPE_ASM_FileStructureExtraGeometry) + WriteUnsignedInteger (PRC_TYPE_ASM_FileStructureExtraGeometry) - EMPTY_CONTENTPRCBASE.serializeContentPRCBase(out); - const uint32_t number_of_contexts = fileStructure->contexts.size(); - WriteUnsignedInteger (number_of_contexts) - for (uint32_t i=0;i<number_of_contexts;i++) - { - SerializeGeometrySummary (contexts[i]) - SerializeContextGraphics (contexts[i]) - } + SerializeEmptyContentPRCBase + const uint32_t number_of_contexts = contexts.size(); + WriteUnsignedInteger (number_of_contexts) + for (uint32_t i=0;i<number_of_contexts;i++) + { + SerializeGeometrySummary (contexts[i]) + SerializeContextGraphics (contexts[i]) + } - UserData(0,0).write(out); + SerializeUserData } -void PRCModelFile::writeData() +void oPRCFile::serializeModelFileData(PRCbitStream &out) { // even though this is technically not part of this section, // it is handled here for convenience - out << (uint32_t)(0); // number of schemas - out << (uint32_t)(PRC_TYPE_ASM_ModelFile); + const uint32_t number_of_schema = 0; + WriteUnsignedInteger (number_of_schema) + WriteUnsignedInteger (PRC_TYPE_ASM_ModelFile) PRCSingleAttribute sa((int32_t)PRCVersion); PRCAttribute a("__PRC_RESERVED_ATTRIBUTE_PRCInternalVersion"); @@ -225,90 +243,65 @@ void PRCModelFile::writeData() cb.addAttribute(a); cb.serializeContentPRCBase(out); - writeUnit(out,true,unit); // unit is specified, and happens to come from a CAD file + SerializeUnit (unit) out << (uint32_t)1; // 1 product occurrence //UUID - out << parent->fileStructures[0]->header.fileStructureUUID[0] - << parent->fileStructures[0]->header.fileStructureUUID[1] - << parent->fileStructures[0]->header.fileStructureUUID[2] - << parent->fileStructures[0]->header.fileStructureUUID[3]; + SerializeCompressedUniqueId( fileStructures[0]->file_structure_uuid ) // index+1 - out << (uint32_t)parent->fileStructures[0]->tree.product_occurrences.size(); + out << (uint32_t)fileStructures[0]->product_occurrences.size(); // active out << true; out << (uint32_t)0; // index in model file - UserData(0,0).write(out); + SerializeUserData } -void makeFileUUID(uint32_t *UUID) +void makeFileUUID(PRCUniqueId& UUID) { // make a UUID static uint32_t count = 0; ++count; // the minimum requirement on UUIDs is that all must be unique in the file - UUID[0] = 0x33595341; // some constant - UUID[1] = time(NULL); // the time - UUID[2] = count; - UUID[3] = 0xa5a55a5a; // Something random, not seeded by the time, would be nice. But for now, a constant + UUID.id0 = 0x33595341; // some constant + UUID.id1 = (uint32_t)time(NULL); // the time + UUID.id2 = count; + UUID.id3 = 0xa5a55a5a; // Something random, not seeded by the time, would be nice. But for now, a constant // maybe add something else to make it more unique // so multiple files can be combined // a hash of some data perhaps? } -void makeAppUUID(uint32_t *UUID) -{ - UUID[0] = UUID[1] = UUID[2] = UUID[3] = 0; -} - -void writeUINT32_T(ostream &out, uint32_t data) +void makeAppUUID(PRCUniqueId& UUID) { -#ifdef WORDS_BIGENDIAN - out.write(((char*)&data)+3,1); - out.write(((char*)&data)+2,1); - out.write(((char*)&data)+1,1); - out.write(((char*)&data)+0,1); -#else - out.write(((char*)&data)+0,1); - out.write(((char*)&data)+1,1); - out.write(((char*)&data)+2,1); - out.write(((char*)&data)+3,1); -#endif + UUID.id0 = UUID.id1 = UUID.id2 = UUID.id3 = 0; } -void PRCUncompressedFile::write(ostream &out) +void PRCUncompressedFile::write(ostream &out) const { if(data!=NULL) { - writeUINT32_T(out,file_size); + WriteUncompressedUnsignedInteger (file_size) out.write((char*)data,file_size); } } -uint32_t PRCUncompressedFile::getSize() +uint32_t PRCUncompressedFile::getSize() const { return sizeof(file_size)+file_size; } -void PRCStartHeader::write(ostream &out) +void PRCStartHeader::serializeStartHeader(ostream &out) const { - out.write("PRC",3); - writeUINT32_T(out,minimal_version_for_read); - writeUINT32_T(out,authoring_version); - writeUINT32_T(out,fileStructureUUID[0]); - writeUINT32_T(out,fileStructureUUID[1]); - writeUINT32_T(out,fileStructureUUID[2]); - writeUINT32_T(out,fileStructureUUID[3]); - - writeUINT32_T(out,applicationUUID[0]); - writeUINT32_T(out,applicationUUID[1]); - writeUINT32_T(out,applicationUUID[2]); - writeUINT32_T(out,applicationUUID[3]); + WriteUncompressedBlock ("PRC",3) + WriteUncompressedUnsignedInteger (minimal_version_for_read) + WriteUncompressedUnsignedInteger (authoring_version) + SerializeFileStructureUncompressedUniqueId( file_structure_uuid ); + SerializeFileStructureUncompressedUniqueId( application_uuid ); } -uint32_t PRCStartHeader::getSize() +uint32_t PRCStartHeader::getStartHeaderSize() const { return 3+(2+2*4)*sizeof(uint32_t); } @@ -316,64 +309,65 @@ uint32_t PRCStartHeader::getSize() void PRCFileStructure::write(ostream &out) { - header.write(out); - uint32_t number_of_uncompressed_files = uncompressedFiles.size(); - writeUINT32_T(out,number_of_uncompressed_files); - for(list<PRCUncompressedFile>::iterator i = uncompressedFiles.begin(); i != uncompressedFiles.end(); i++) - i->write(out); - globals.write(out); - tree.write(out); - tessellations.write(out); - geometry.write(out); - extraGeometry.write(out); -} - + // SerializeFileStructureHeader + SerializeStartHeader + SerializeUncompressedFiles + globals_out.write(out); + tree_out.write(out); + tessellations_out.write(out); + geometry_out.write(out); + extraGeometry_out.write(out); +} + +#define SerializeFileStructureGlobals serializeFileStructureGlobals(globals_out); globals_out.compress(); sizes[1]=globals_out.getSize(); +#define SerializeFileStructureTree serializeFileStructureTree(tree_out); tree_out.compress(); sizes[2]=tree_out.getSize(); +#define SerializeFileStructureTessellation serializeFileStructureTessellation(tessellations_out); tessellations_out.compress(); sizes[3]=tessellations_out.getSize(); +#define SerializeFileStructureGeometry serializeFileStructureGeometry(geometry_out); geometry_out.compress(); sizes[4]=geometry_out.getSize(); +#define SerializeFileStructureExtraGeometry serializeFileStructureExtraGeometry(extraGeometry_out); extraGeometry_out.compress(); sizes[5]=extraGeometry_out.getSize(); +#define FlushSerialization resetGraphicsAndName(); void PRCFileStructure::prepare() { - globals.prepare(); - resetGraphicsAndName(); + uint32_t size = 0; + size += getStartHeaderSize(); + size += sizeof(uint32_t); + for(PRCUncompressedFileList::const_iterator it = uncompressed_files.begin(); it != uncompressed_files.end(); it++) + size += (*it)->getSize(); + sizes[0]=size; - tree.prepare(); - resetGraphicsAndName(); + SerializeFileStructureGlobals + FlushSerialization - tessellations.prepare(); - resetGraphicsAndName(); + SerializeFileStructureTree + FlushSerialization - geometry.prepare(); - resetGraphicsAndName(); + SerializeFileStructureTessellation + FlushSerialization - extraGeometry.prepare(); - resetGraphicsAndName(); + SerializeFileStructureGeometry + FlushSerialization + + SerializeFileStructureExtraGeometry + FlushSerialization } uint32_t PRCFileStructure::getSize() { uint32_t size = 0; - size += header.getSize(); - size += sizeof(uint32_t); - for(list<PRCUncompressedFile>::iterator i = uncompressedFiles.begin(); i != uncompressedFiles.end(); i++) - size += i->getSize(); - size += globals.getSize(); - size += tree.getSize(); - size += tessellations.getSize(); - size += geometry.getSize(); - size += extraGeometry.getSize(); + for(size_t i=0; i<6; i++) + size += sizes[i]; return size; } void PRCFileStructureInformation::write(ostream &out) { - writeUINT32_T(out,UUID[0]); - writeUINT32_T(out,UUID[1]); - writeUINT32_T(out,UUID[2]); - writeUINT32_T(out,UUID[3]); + SerializeFileStructureUncompressedUniqueId( UUID ); - writeUINT32_T(out,reserved); - writeUINT32_T(out,number_of_offsets); + WriteUncompressedUnsignedInteger (reserved) + WriteUncompressedUnsignedInteger (number_of_offsets) for(uint32_t i = 0; i < number_of_offsets; ++i) { - writeUINT32_T(out,offsets[i]); + WriteUncompressedUnsignedInteger (offsets[i]) } } @@ -384,28 +378,25 @@ uint32_t PRCFileStructureInformation::getSize() void PRCHeader::write(ostream &out) { - startHeader.write(out); - writeUINT32_T(out,number_of_file_structures); + SerializeStartHeader + WriteUncompressedUnsignedInteger (number_of_file_structures) for(uint32_t i = 0; i < number_of_file_structures; ++i) { fileStructureInformation[i].write(out); } - writeUINT32_T(out,model_file_offset); - writeUINT32_T(out,file_size); - uint32_t number_of_uncompressed_files = uncompressedFiles.size(); - writeUINT32_T(out,number_of_uncompressed_files); - for(list<PRCUncompressedFile>::iterator i = uncompressedFiles.begin(); i != uncompressedFiles.end(); i++) - i->write(out); + WriteUncompressedUnsignedInteger (model_file_offset) + WriteUncompressedUnsignedInteger (file_size) + SerializeUncompressedFiles } uint32_t PRCHeader::getSize() { - uint32_t size = startHeader.getSize() + sizeof(uint32_t); + uint32_t size = getStartHeaderSize() + sizeof(uint32_t); for(uint32_t i = 0; i < number_of_file_structures; ++i) size += fileStructureInformation[i].getSize(); size += 3*sizeof(uint32_t); - for(list<PRCUncompressedFile>::iterator i = uncompressedFiles.begin(); i != uncompressedFiles.end(); i++) - size += i->getSize(); + for(PRCUncompressedFileList::const_iterator it = uncompressed_files.begin(); it != uncompressed_files.end(); it++) + size += (*it)->getSize(); return size; } @@ -419,52 +410,58 @@ void oPRCFile::doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definitio { if(!group.lines.empty()) { - bool same_color = true; - const PRCRgbColor &color = group.lines.front().color; - for(PRCtesslineList::const_iterator lit=group.lines.begin(); lit!=group.lines.end(); lit++) - if(color!=lit->color) - { - same_color = false; - break; - } - map<PRCVector3d,uint32_t> points; - PRC3DWireTess *tess = new PRC3DWireTess(); - if(!same_color) - { - tess->is_segment_color = true; - tess->is_rgba = false; - } - for(PRCtesslineList::const_iterator lit=group.lines.begin(); lit!=group.lines.end(); lit++) + for(PRCtesslineMap::const_iterator wit=group.lines.begin(); wit!=group.lines.end(); wit++) { - tess->wire_indexes.push_back(lit->point.size()); - for(uint32_t i=0; i<lit->point.size(); i++) - { - map<PRCVector3d,uint32_t>::iterator pPoint = points.find(lit->point[i]); - if(pPoint!=points.end()) - tess->wire_indexes.push_back(pPoint->second); - else + bool same_color = true; + const PRCtesslineList& lines = wit->second; + const PRCRgbColor &color = lines.front().color; + for(PRCtesslineList::const_iterator lit=lines.begin(); lit!=lines.end(); lit++) + if(color!=lit->color) { - uint32_t point_index = m1; - points.insert(make_pair(lit->point[i],(point_index = tess->coordinates.size()))); - tess->wire_indexes.push_back(point_index); - tess->coordinates.push_back(lit->point[i].x); - tess->coordinates.push_back(lit->point[i].y); - tess->coordinates.push_back(lit->point[i].z); + same_color = false; + break; } - if(!same_color && i>0) + map<PRCVector3d,uint32_t> points; + PRC3DWireTess *tess = new PRC3DWireTess(); + if(!same_color) + { + tess->is_segment_color = true; + tess->is_rgba = false; + } + for(PRCtesslineList::const_iterator lit=lines.begin(); lit!=lines.end(); lit++) + { + tess->wire_indexes.push_back(lit->point.size()); + for(uint32_t i=0; i<lit->point.size(); i++) { - tess->rgba_vertices.push_back((uint8_t)(255*lit->color.red)); - tess->rgba_vertices.push_back((uint8_t)(255*lit->color.green)); - tess->rgba_vertices.push_back((uint8_t)(255*lit->color.blue)); + map<PRCVector3d,uint32_t>::iterator pPoint = points.find(lit->point[i]); + if(pPoint!=points.end()) + tess->wire_indexes.push_back(pPoint->second); + else + { + uint32_t point_index = m1; + points.insert(make_pair(lit->point[i],(point_index = tess->coordinates.size()))); + tess->wire_indexes.push_back(point_index); + tess->coordinates.push_back(lit->point[i].x); + tess->coordinates.push_back(lit->point[i].y); + tess->coordinates.push_back(lit->point[i].z); + } + if(!same_color && i>0) + { + tess->rgba_vertices.push_back(byte(lit->color.red)); + tess->rgba_vertices.push_back(byte(lit->color.green)); + tess->rgba_vertices.push_back(byte(lit->color.blue)); + } } } + const uint32_t tess_index = add3DWireTess(tess); + PRCPolyWire *polyWire = new PRCPolyWire(); + polyWire->index_tessellation = tess_index; + if(same_color) + polyWire->index_of_line_style = addColourWidth(RGBAColour(color.red,color.green,color.blue),wit->first); + else + polyWire->index_of_line_style = addColourWidth(RGBAColour(1,1,1),wit->first); + part_definition->addPolyWire(polyWire); } - const uint32_t tess_index = add3DWireTess(tess); - PRCPolyWire *polyWire = new PRCPolyWire(); - polyWire->index_tessellation = tess_index; - if(same_color) - polyWire->index_of_line_style = addColour(RGBAColour(color.red,color.green,color.blue)); - part_definition->addPolyWire(polyWire); } // make rectangles pairs of triangles in a tesselation if(!group.rectangles.empty()) @@ -488,7 +485,7 @@ void oPRCFile::doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definitio uint32_t vertex_indices[4]; for(size_t i = (degenerate?1:0); i < 4; ++i) { - map<PRCVector3d,uint32_t>::iterator pPoint = points.find(rit->vertices[i]); + map<PRCVector3d,uint32_t>::const_iterator pPoint = points.find(rit->vertices[i]); if(pPoint!=points.end()) vertex_indices[i] = pPoint->second; else @@ -535,7 +532,7 @@ void oPRCFile::doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definitio part_definition->addPolyBrepModel(polyBrepModel); } } - + if(!group.points.empty()) { for(PRCpointsetMap::const_iterator pit=group.points.begin(); pit!=group.points.end(); pit++) @@ -547,6 +544,30 @@ void oPRCFile::doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definitio } } + if(!group.pointsets.empty()) + { + for(std::vector<PRCPointSet*>::iterator pit=group.pointsets.begin(); pit!=group.pointsets.end(); pit++) + { + part_definition->addPointSet(*pit); + } + } + + if(!group.polymodels.empty()) + { + for(std::vector<PRCPolyBrepModel*>::iterator pit=group.polymodels.begin(); pit!=group.polymodels.end(); pit++) + { + part_definition->addPolyBrepModel(*pit); + } + } + + if(!group.polywires.empty()) + { + for(std::vector<PRCPolyWire*>::iterator pit=group.polywires.begin(); pit!=group.polywires.end(); pit++) + { + part_definition->addPolyWire(*pit); + } + } + if(!group.wires.empty()) { PRCTopoContext *wireContext = NULL; @@ -590,7 +611,7 @@ void oPRCFile::doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definitio for(PRCfaceList::iterator fit=faces.begin(); fit!=faces.end(); fit++) { - if(fit->transform || group.options.do_break || + if(fit->transform || group.options.do_break || (fit->transparent && !group.options.no_break)) { PRCShell *shell = new PRCShell; @@ -600,7 +621,7 @@ void oPRCFile::doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definitio PRCBrepData *body = new PRCBrepData; body->addConnex(connex); const uint32_t body_index = context->addBrepData(body); - + PRCBrepModel *brepmodel = new PRCBrepModel(); brepmodel->index_of_line_style = fit->style; brepmodel->context_id = context_index; @@ -653,13 +674,13 @@ void oPRCFile::doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definitio PRCTopoContext *context = NULL; const uint32_t context_index = getTopoContext(context); PRCCompressedBrepData *body = new PRCCompressedBrepData; - + body->serial_tolerance=group.options.compression; body->brep_data_compressed_tolerance=0.1*group.options.compression; for(PRCcompfaceList::const_iterator fit=compfaces.begin(); fit!=compfaces.end(); fit++) { - if(group.options.do_break || + if(group.options.do_break || (fit->transparent && !group.options.no_break)) { PRCCompressedBrepData *body = new PRCCompressedBrepData; @@ -737,7 +758,7 @@ void oPRCFile::doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definitio part_definition->representation_item.clear(); parent_part_definition->addSet(set); delete product_occurrence; - delete part_definition; + delete part_definition; } // Third option - create product else if ( !product_occurrence->index_son_occurrence.empty() || !part_definition->representation_item.empty()) @@ -763,7 +784,7 @@ void oPRCFile::doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definitio delete product_occurrence; delete part_definition; } - + } bool oPRCFile::finish() @@ -773,7 +794,7 @@ bool oPRCFile::finish() // write each section's bit data fileStructures[0]->prepare(); - modelFile.prepare(); + SerializeModelFileData // create the header @@ -782,41 +803,29 @@ bool oPRCFile::finish() header.fileStructureInformation = new PRCFileStructureInformation[number_of_file_structures]; for(uint32_t i = 0; i < number_of_file_structures; ++i) { - header.fileStructureInformation[i].UUID[0] = fileStructures[i]->header.fileStructureUUID[0]; - header.fileStructureInformation[i].UUID[1] = fileStructures[i]->header.fileStructureUUID[1]; - header.fileStructureInformation[i].UUID[2] = fileStructures[i]->header.fileStructureUUID[2]; - header.fileStructureInformation[i].UUID[3] = fileStructures[i]->header.fileStructureUUID[3]; + header.fileStructureInformation[i].UUID = fileStructures[i]->file_structure_uuid; header.fileStructureInformation[i].reserved = 0; header.fileStructureInformation[i].number_of_offsets = 6; header.fileStructureInformation[i].offsets = new uint32_t[6]; } - header.startHeader.minimal_version_for_read = PRCVersion; - header.startHeader.authoring_version = PRCVersion; - makeFileUUID(header.startHeader.fileStructureUUID); - makeAppUUID(header.startHeader.applicationUUID); + header.minimal_version_for_read = PRCVersion; + header.authoring_version = PRCVersion; + makeFileUUID(header.file_structure_uuid); + makeAppUUID(header.application_uuid); header.file_size = getSize(); - header.model_file_offset = header.file_size - modelFile.getSize(); + header.model_file_offset = header.file_size - modelFile_out.getSize(); uint32_t currentOffset = header.getSize(); for(uint32_t i = 0; i < number_of_file_structures; ++i) { - header.fileStructureInformation[i].offsets[0] = currentOffset; // header offset - currentOffset += fileStructures[i]->header.getSize() + sizeof(uint32_t); - for(list<PRCUncompressedFile>::iterator j = fileStructures[i]->uncompressedFiles.begin(); j != fileStructures[i]->uncompressedFiles.end(); j++) - currentOffset += j->getSize(); - header.fileStructureInformation[i].offsets[1] = currentOffset; // globals offset - currentOffset += fileStructures[i]->globals.getSize(); - header.fileStructureInformation[i].offsets[2] = currentOffset; // tree offset - currentOffset += fileStructures[i]->tree.getSize(); - header.fileStructureInformation[i].offsets[3] = currentOffset; // tessellations offset - currentOffset += fileStructures[i]->tessellations.getSize(); - header.fileStructureInformation[i].offsets[4] = currentOffset; // geometry offset - currentOffset += fileStructures[i]->geometry.getSize(); - header.fileStructureInformation[i].offsets[5] = currentOffset; // extra geometry offset - currentOffset += fileStructures[i]->extraGeometry.getSize(); + for(size_t j=0; j<6; j++) + { + header.fileStructureInformation[i].offsets[j] = currentOffset; + currentOffset += fileStructures[i]->sizes[j]; + } } // write the data @@ -827,7 +836,7 @@ bool oPRCFile::finish() fileStructures[i]->write(output); } - modelFile.write(output); + modelFile_out.write(output); output.flush(); for(uint32_t i = 0; i < number_of_file_structures; ++i) @@ -846,18 +855,16 @@ uint32_t oPRCFile::getSize() size += fileStructures[i]->getSize(); } - size += modelFile.getSize(); + size += modelFile_out.getSize(); return size; } -#define REPORT_ERROR( value ) { cerr << value << endl; return m1; } - uint32_t PRCFileStructure::addPicture(EPRCPictureDataFormat format, uint32_t size, const uint8_t *p, uint32_t width, uint32_t height, string name) { if(size==0 || p==NULL) - REPORT_ERROR( "image not set" ) + { cerr << "image not set" << endl; return m1; } PRCPicture picture(name); - PRCUncompressedFile uncompressedFile; + PRCUncompressedFile* uncompressed_file = new PRCUncompressedFile; uint32_t components=0; uint8_t *data = NULL; switch(format) @@ -871,27 +878,27 @@ uint32_t PRCFileStructure::addPicture(EPRCPictureDataFormat format, uint32_t siz case KEPRCPicture_BITMAP_GREYA_BYTE: components = 2; if(width==0 || height==0) - REPORT_ERROR( "width or height parameter not set" ) + { cerr << "width or height parameter not set" << endl; return m1; } if (size < width*height*components) - REPORT_ERROR( "image too small" ) - + { cerr << "image too small" << endl; return m1; } + { uint32_t compressedDataSize = 0; const int CHUNK= 1024; // is this reasonable? - + z_stream strm; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; if(deflateInit(&strm,Z_DEFAULT_COMPRESSION) != Z_OK) - REPORT_ERROR ( "Compression initialization failed" ) + { cerr << "Compression initialization failed" << endl; return m1; } unsigned int sizeAvailable = deflateBound(&strm,size); uint8_t *compressedData = (uint8_t*) malloc(sizeAvailable); strm.avail_in = size; strm.next_in = (unsigned char*)p; strm.next_out = (unsigned char*)compressedData; strm.avail_out = sizeAvailable; - + int code; unsigned int chunks = 0; while((code = deflate(&strm,Z_FINISH)) == Z_OK) @@ -905,79 +912,79 @@ uint32_t PRCFileStructure::addPicture(EPRCPictureDataFormat format, uint32_t siz sizeAvailable += CHUNK; } compressedDataSize = sizeAvailable-strm.avail_out; - + if(code != Z_STREAM_END) { deflateEnd(&strm); free(compressedData); - REPORT_ERROR ( "Compression error" ) + { cerr << "Compression error" << endl; return m1; } } - + deflateEnd(&strm); size = compressedDataSize; data = new uint8_t[compressedDataSize]; memcpy(data, compressedData, compressedDataSize); free(compressedData); } - uncompressedFiles.push_back(uncompressedFile); - uncompressedFiles.back().file_size = size; - uncompressedFiles.back().data = data; + uncompressed_files.push_back(uncompressed_file); + uncompressed_files.back()->file_size = size; + uncompressed_files.back()->data = data; picture.format = format; - picture.uncompressed_file_index = uncompressedFiles.size()-1; + picture.uncompressed_file_index = uncompressed_files.size()-1; picture.pixel_width = width; picture.pixel_height = height; - globals.pictures.push_back(picture); - return globals.pictures.size()-1; + pictures.push_back(picture); + return pictures.size()-1; break; case KEPRCPicture_PNG: case KEPRCPicture_JPG: data = new uint8_t[size]; memcpy(data, p, size); - uncompressedFiles.push_back(uncompressedFile); - uncompressedFiles.back().file_size = size; - uncompressedFiles.back().data = data; + uncompressed_files.push_back(uncompressed_file); + uncompressed_files.back()->file_size = size; + uncompressed_files.back()->data = data; picture.format = format; - picture.uncompressed_file_index = uncompressedFiles.size()-1; + picture.uncompressed_file_index = uncompressed_files.size()-1; picture.pixel_width = 0; // width and height are ignored for JPG and PNG pictures - but let us keep things clean picture.pixel_height = 0; - globals.pictures.push_back(picture); - return globals.pictures.size()-1; + pictures.push_back(picture); + return pictures.size()-1; break; default: - REPORT_ERROR( "unknown picture format" ) + { cerr << "unknown picture format" << endl; return m1; } } return m1; } -#undef REPORT_ERROR -uint32_t PRCFileStructure::addTextureDefinition(PRCTextureDefinition *pTextureDefinition) +uint32_t PRCFileStructure::addTextureDefinition(PRCTextureDefinition*& pTextureDefinition) { - globals.texture_definitions.push_back(pTextureDefinition); - return globals.texture_definitions.size()-1; + texture_definitions.push_back(pTextureDefinition); + pTextureDefinition = NULL; + return texture_definitions.size()-1; } uint32_t PRCFileStructure::addRgbColor(const PRCRgbColor &color) { - globals.colors.push_back(color); - return 3*(globals.colors.size()-1); + colors.push_back(color); + return 3*(colors.size()-1); } uint32_t PRCFileStructure::addRgbColorUnique(const PRCRgbColor &color) { - for(uint32_t i = 0; i < globals.colors.size(); ++i) + for(uint32_t i = 0; i < colors.size(); ++i) { - if(globals.colors[i] == color) + if(colors[i] == color) return 3*i; } - globals.colors.push_back(color); - return 3*(globals.colors.size()-1); + colors.push_back(color); + return 3*(colors.size()-1); } uint32_t oPRCFile::addColor(const PRCRgbColor &color) { - PRCcolorMap::iterator pColor = colorMap.find(color); + PRCcolorMap::const_iterator pColor = colorMap.find(color); uint32_t color_index = m1; if(pColor!=colorMap.end()) return pColor->second; @@ -989,11 +996,11 @@ uint32_t oPRCFile::addColor(const PRCRgbColor &color) uint32_t oPRCFile::addColour(const RGBAColour &colour) { - PRCcolourMap::iterator pColour = colourMap.find(colour); + PRCcolourMap::const_iterator pColour = colourMap.find(colour); if(pColour!=colourMap.end()) return pColour->second; const uint32_t color_index = addColor(PRCRgbColor(colour.R, colour.G, colour.B)); - PRCStyle *style = new PRCStyle(); + PRCStyle *style = new PRCStyle(); style->line_width = 1.0; style->is_vpicture = false; style->line_pattern_vpicture_index = 0; @@ -1007,11 +1014,32 @@ uint32_t oPRCFile::addColour(const RGBAColour &colour) return style_index; } +uint32_t oPRCFile::addColourWidth(const RGBAColour &colour, double width) +{ + RGBAColourWidth colourwidth(colour.R, colour.G, colour.B, colour.A, width); + PRCcolourwidthMap::const_iterator pColour = colourwidthMap.find(colourwidth); + if(pColour!=colourwidthMap.end()) + return pColour->second; + const uint32_t color_index = addColor(PRCRgbColor(colour.R, colour.G, colour.B)); + PRCStyle *style = new PRCStyle(); + style->line_width = width; + style->is_vpicture = false; + style->line_pattern_vpicture_index = 0; + style->is_material = false; + style->color_material_index = color_index; + style->is_transparency_defined = (colour.A < 1.0); + style->transparency = (uint8_t)(colour.A * 256); + style->additional = 0; + const uint32_t style_index = fileStructures[0]->addStyle(style); + colourwidthMap.insert(make_pair(colourwidth,style_index)); + return style_index; +} + uint32_t oPRCFile::addTransform(PRCGeneralTransformation3d*& transform) { if(!transform) return m1; - PRCtransformMap::iterator pTransform = transformMap.find(*transform); + PRCtransformMap::const_iterator pTransform = transformMap.find(*transform); if(pTransform!=transformMap.end()) return pTransform->second; PRCCoordinateSystem *coordinateSystem = new PRCCoordinateSystem(); @@ -1024,10 +1052,10 @@ uint32_t oPRCFile::addTransform(PRCGeneralTransformation3d*& transform) uint32_t oPRCFile::addMaterial(const PRCmaterial &material) { - PRCmaterialMap::iterator pMaterial = materialMap.find(material); + PRCmaterialMap::const_iterator pMaterial = materialMap.find(material); if(pMaterial!=materialMap.end()) return pMaterial->second; - PRCMaterialGeneric *materialGeneric = new PRCMaterialGeneric(); + PRCMaterialGeneric *materialGeneric = new PRCMaterialGeneric(); const PRCRgbColor ambient(material.ambient.R, material.ambient.G, material.ambient.B); materialGeneric->ambient = addColor(ambient); const PRCRgbColor diffuse(material.diffuse.R, material.diffuse.G, material.diffuse.B); @@ -1041,17 +1069,36 @@ uint32_t oPRCFile::addMaterial(const PRCmaterial &material) materialGeneric->diffuse_alpha = material.diffuse.A; materialGeneric->emissive_alpha = material.emissive.A; materialGeneric->specular_alpha = material.specular.A; - const uint32_t material_index = fileStructures[0]->addMaterialGeneric(materialGeneric); - PRCStyle *style = new PRCStyle(); + const uint32_t material_index = addMaterialGeneric(materialGeneric); + PRCStyle *style = new PRCStyle(); style->line_width = 0.0; style->is_vpicture = false; style->line_pattern_vpicture_index = 0; style->is_material = true; - style->color_material_index = material_index; style->is_transparency_defined = (material.alpha < 1.0); style->transparency = (uint8_t)(material.alpha * 256); style->additional = 0; - const uint32_t style_index = fileStructures[0]->addStyle(style); + if(material.picture!=NULL && material.picture_width!=0 && material.picture_height!=0) + { + const uint32_t picture_index = + addPicture((material.picture_rgba?KEPRCPicture_BITMAP_RGBA_BYTE:KEPRCPicture_BITMAP_RGB_BYTE), + material.picture_width*material.picture_height*(material.picture_rgba?4:3),material.picture,material.picture_width,material.picture_height); + PRCTextureDefinition *textureDefinition = new PRCTextureDefinition; + textureDefinition->picture_index = picture_index; + textureDefinition->texture_function = material.picture_replace ? KEPRCTextureFunction_Replace : KEPRCTextureFunction_Modulate; + textureDefinition->texture_wrapping_mode_S = KEPRCTextureWrappingMode_ClampToEdge; + textureDefinition->texture_wrapping_mode_T = KEPRCTextureWrappingMode_ClampToEdge; + textureDefinition->texture_mapping_attribute_components = material.picture_rgba ? PRC_TEXTURE_MAPPING_COMPONENTS_RGBA : PRC_TEXTURE_MAPPING_COMPONENTS_RGB; + const uint32_t texture_definition_index = addTextureDefinition(textureDefinition); + PRCTextureApplication *textureApplication = new PRCTextureApplication; + textureApplication->material_generic_index = material_index; + textureApplication->texture_definition_index = texture_definition_index; + const uint32_t texture_application_index = addTextureApplication(textureApplication); + style->color_material_index = texture_application_index; + } + else + style->color_material_index = material_index; + const uint32_t style_index = addStyle(style); materialMap.insert(make_pair(material,style_index)).first; return style_index; } @@ -1125,23 +1172,421 @@ PRCgroup& oPRCFile::findGroup() face.transparent = m.alpha < 1.0; \ face.style = addMaterial(m); -void oPRCFile::addPoint(const double P[3], const RGBAColour &c) +void oPRCFile::addPoint(const double P[3], const RGBAColour &c, double w) { PRCgroup &group = findGroup(); - group.points[addColour(c)].push_back(PRCVector3d(P[0],P[1],P[2])); + group.points[addColourWidth(c,w)].push_back(PRCVector3d(P[0],P[1],P[2])); } -void oPRCFile::addLine(uint32_t n, const double P[][3], const RGBAColour &c) +void oPRCFile::addPoints(uint32_t n, const double P[][3], const RGBAColour &c, double w) +{ + if(n==0 || P==NULL) + return; + PRCgroup &group = findGroup(); + PRCPointSet *pointset = new PRCPointSet(); + group.pointsets.push_back(pointset); + pointset->index_of_line_style = addColourWidth(c,w); + for(uint32_t i=0; i<n; i++) + pointset->point.push_back(PRCVector3d(P[i][0],P[i][1],P[i][2])); +} + +void oPRCFile::addTriangles(uint32_t nP, const double P[][3], uint32_t nI, const uint32_t PI[][3], const PRCmaterial &m, + uint32_t nN, const double N[][3], const uint32_t NI[][3], + uint32_t nT, const double T[][2], const uint32_t TI[][3], + uint32_t nC, const RGBAColour C[], const uint32_t CI[][3], + uint32_t nM, const PRCmaterial M[], const uint32_t MI[]) +{ + if(nP==0 || P==NULL || nI==0 || PI==NULL) + return; + PRCgroup &group = findGroup(); + + const bool triangle_color = (nM != 0 && M != NULL && MI != NULL); + const bool vertex_color = (nC != 0 && C != NULL && CI != NULL); + const bool has_normals = (nN != 0 && N != NULL && NI != NULL); + const bool textured = (nT != 0 && T != NULL && TI != NULL); + + PRC3DTess *tess = new PRC3DTess(); + PRCTessFace *tessFace = new PRCTessFace(); + tessFace->used_entities_flag = textured ? PRC_FACETESSDATA_TriangleTextured : PRC_FACETESSDATA_Triangle; + tessFace->number_of_texture_coordinate_indexes = textured ? 1 : 0; + for(uint32_t i=0; i<nP; i++) + { + tess->coordinates.push_back(P[i][0]); + tess->coordinates.push_back(P[i][1]); + tess->coordinates.push_back(P[i][2]); + } + if(has_normals) + for(uint32_t i=0; i<nN; i++) + { + tess->normal_coordinate.push_back(N[i][0]); + tess->normal_coordinate.push_back(N[i][1]); + tess->normal_coordinate.push_back(N[i][2]); + } + if(textured) + for(uint32_t i=0; i<nT; i++) + { + tess->texture_coordinate.push_back(T[i][0]); + tess->texture_coordinate.push_back(T[i][1]); + } + for(uint32_t i=0; i<nI; i++) + { + if(has_normals) + tess->triangulated_index.push_back(3*NI[i][0]); + if(textured) + tess->triangulated_index.push_back(2*TI[i][0]); + tess->triangulated_index.push_back(3*PI[i][0]); + if(has_normals) + tess->triangulated_index.push_back(3*NI[i][1]); + if(textured) + tess->triangulated_index.push_back(2*TI[i][1]); + tess->triangulated_index.push_back(3*PI[i][1]); + if(has_normals) + tess->triangulated_index.push_back(3*NI[i][2]); + if(textured) + tess->triangulated_index.push_back(2*TI[i][2]); + tess->triangulated_index.push_back(3*PI[i][2]); + } + tessFace->sizes_triangulated.push_back(nI); + if(triangle_color) + { +#ifdef __GNUC__ + uint32_t styles[nM]; +#else + std::vector<uint32_t> styles(nM); +#endif + for(uint32_t i=0; i<nM; i++) + styles[i] = addMaterial(M[i]); + for(uint32_t i=0; i<nI; i++) + tessFace->line_attributes.push_back(styles[MI[i]]); + } + else + tessFace->line_attributes.push_back(addMaterial(m)); + if(vertex_color) + { + tessFace->is_rgba=false; + for(uint32_t i=0; i<nI; i++) + if(1.0 != C[CI[i][0]].A || 1.0 != C[CI[i][1]].A || 1.0 != C[CI[i][2]].A) + { + tessFace->is_rgba=true; + break; + } + + for(uint32_t i=0; i<nI; i++) + { + tessFace->rgba_vertices.push_back(byte(C[CI[i][0]].R)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][0]].G)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][0]].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[CI[i][0]].A)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].R)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].G)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].A)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][2]].R)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][2]].G)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][2]].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[CI[i][2]].A)); + } + } + tess->addTessFace(tessFace); + const uint32_t tess_index = add3DTess(tess); + PRCPolyBrepModel *polyBrepModel = new PRCPolyBrepModel(); + polyBrepModel->index_tessellation = tess_index; + polyBrepModel->is_closed = group.options.closed; +// if(!triangle_color) +// polyBrepModel->index_of_line_style = addMaterial(m); + group.polymodels.push_back(polyBrepModel); +} + +void oPRCFile::addQuads(uint32_t nP, const double P[][3], uint32_t nI, const uint32_t PI[][4], const PRCmaterial &m, + uint32_t nN, const double N[][3], const uint32_t NI[][4], + uint32_t nT, const double T[][2], const uint32_t TI[][4], + uint32_t nC, const RGBAColour C[], const uint32_t CI[][4], + uint32_t nM, const PRCmaterial M[], const uint32_t MI[]) +{ + if(nP==0 || P==NULL || nI==0 || PI==NULL) + return; + PRCgroup &group = findGroup(); + + const bool triangle_color = (nM != 0 && M != NULL && MI != NULL); + const bool vertex_color = (nC != 0 && C != NULL && CI != NULL); + const bool has_normals = (nN != 0 && N != NULL && NI != NULL); + const bool textured = (nT != 0 && T != NULL && TI != NULL); + + PRC3DTess *tess = new PRC3DTess(); + PRCTessFace *tessFace = new PRCTessFace(); + tessFace->used_entities_flag = textured ? PRC_FACETESSDATA_TriangleTextured : PRC_FACETESSDATA_Triangle; + tessFace->number_of_texture_coordinate_indexes = textured ? 1 : 0; + for(uint32_t i=0; i<nP; i++) + { + tess->coordinates.push_back(P[i][0]); + tess->coordinates.push_back(P[i][1]); + tess->coordinates.push_back(P[i][2]); + } + if(has_normals) + for(uint32_t i=0; i<nN; i++) + { + tess->normal_coordinate.push_back(N[i][0]); + tess->normal_coordinate.push_back(N[i][1]); + tess->normal_coordinate.push_back(N[i][2]); + } + if(textured) + for(uint32_t i=0; i<nT; i++) + { + tess->texture_coordinate.push_back(T[i][0]); + tess->texture_coordinate.push_back(T[i][1]); + } + for(uint32_t i=0; i<nI; i++) + { + // first triangle + if(has_normals) + tess->triangulated_index.push_back(3*NI[i][0]); + if(textured) + tess->triangulated_index.push_back(2*TI[i][0]); + tess->triangulated_index.push_back(3*PI[i][0]); + if(has_normals) + tess->triangulated_index.push_back(3*NI[i][1]); + if(textured) + tess->triangulated_index.push_back(2*TI[i][1]); + tess->triangulated_index.push_back(3*PI[i][1]); + if(has_normals) + tess->triangulated_index.push_back(3*NI[i][3]); + if(textured) + tess->triangulated_index.push_back(2*TI[i][3]); + tess->triangulated_index.push_back(3*PI[i][3]); + // second triangle + if(has_normals) + tess->triangulated_index.push_back(3*NI[i][1]); + if(textured) + tess->triangulated_index.push_back(2*TI[i][1]); + tess->triangulated_index.push_back(3*PI[i][1]); + if(has_normals) + tess->triangulated_index.push_back(3*NI[i][2]); + if(textured) + tess->triangulated_index.push_back(2*TI[i][2]); + tess->triangulated_index.push_back(3*PI[i][2]); + if(has_normals) + tess->triangulated_index.push_back(3*NI[i][3]); + if(textured) + tess->triangulated_index.push_back(2*TI[i][3]); + tess->triangulated_index.push_back(3*PI[i][3]); + } + tessFace->sizes_triangulated.push_back(2*nI); + if(triangle_color) + { +#ifdef __GNUC__ + uint32_t styles[nM]; +#else + std::vector<uint32_t> styles(nM); +#endif + for(uint32_t i=0; i<nM; i++) + styles[i] = addMaterial(M[i]); + for(uint32_t i=0; i<nI; i++) + { + tessFace->line_attributes.push_back(styles[MI[i]]); + tessFace->line_attributes.push_back(styles[MI[i]]); + } + } + else + tessFace->line_attributes.push_back(addMaterial(m)); + if(vertex_color) + { + tessFace->is_rgba=false; + for(uint32_t i=0; i<nI; i++) + if(1.0 != C[CI[i][0]].A || 1.0 != C[CI[i][1]].A || 1.0 != C[CI[i][2]].A) + { + tessFace->is_rgba=true; + break; + } + + for(uint32_t i=0; i<nI; i++) + { + // first triangle + tessFace->rgba_vertices.push_back(byte(C[CI[i][0]].R)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][0]].G)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][0]].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[CI[i][0]].A)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].R)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].G)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].A)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][3]].R)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][3]].G)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][3]].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[CI[i][3]].A)); + // second triangle + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].R)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].G)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[CI[i][1]].A)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][2]].R)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][2]].G)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][2]].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[CI[i][2]].A)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][3]].R)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][3]].G)); + tessFace->rgba_vertices.push_back(byte(C[CI[i][3]].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[CI[i][3]].A)); + } + } + tess->addTessFace(tessFace); + const uint32_t tess_index = add3DTess(tess); + PRCPolyBrepModel *polyBrepModel = new PRCPolyBrepModel(); + polyBrepModel->index_tessellation = tess_index; + polyBrepModel->is_closed = group.options.closed; +// if(!triangle_color) +// polyBrepModel->index_of_line_style = addMaterial(m); + group.polymodels.push_back(polyBrepModel); +} + +void oPRCFile::addQuad(const double P[][3], const RGBAColour C[]) +{ + PRCgroup &group = findGroup(); + + PRC3DTess *tess = new PRC3DTess(); + PRCTessFace *tessFace = new PRCTessFace(); + tessFace->used_entities_flag = PRC_FACETESSDATA_Triangle; + tessFace->number_of_texture_coordinate_indexes = 0; + for(uint32_t i=0; i < 4; i++) + { + tess->coordinates.push_back(P[i][0]); + tess->coordinates.push_back(P[i][1]); + tess->coordinates.push_back(P[i][2]); + } + + tess->triangulated_index.push_back(3*0); + tess->triangulated_index.push_back(3*1); + tess->triangulated_index.push_back(3*2); + + tess->triangulated_index.push_back(3*1); + tess->triangulated_index.push_back(3*3); + tess->triangulated_index.push_back(3*2); + + tessFace->sizes_triangulated.push_back(2); + + tessFace->is_rgba= + (C[0].A != 1.0 || C[1].A != 1.0 || C[2].A != 1.0 || C[3].A != 1.0); + + // first triangle + tessFace->rgba_vertices.push_back(byte(C[0].R)); + tessFace->rgba_vertices.push_back(byte(C[0].G)); + tessFace->rgba_vertices.push_back(byte(C[0].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[0].A)); + + tessFace->rgba_vertices.push_back(byte(C[1].R)); + tessFace->rgba_vertices.push_back(byte(C[1].G)); + tessFace->rgba_vertices.push_back(byte(C[1].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[1].A)); + + tessFace->rgba_vertices.push_back(byte(C[2].R)); + tessFace->rgba_vertices.push_back(byte(C[2].G)); + tessFace->rgba_vertices.push_back(byte(C[2].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[2].A)); + + // second triangle + tessFace->rgba_vertices.push_back(byte(C[1].R)); + tessFace->rgba_vertices.push_back(byte(C[1].G)); + tessFace->rgba_vertices.push_back(byte(C[1].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[1].A)); + + tessFace->rgba_vertices.push_back(byte(C[3].R)); + tessFace->rgba_vertices.push_back(byte(C[3].G)); + tessFace->rgba_vertices.push_back(byte(C[3].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[3].A)); + + tessFace->rgba_vertices.push_back(byte(C[2].R)); + tessFace->rgba_vertices.push_back(byte(C[2].G)); + tessFace->rgba_vertices.push_back(byte(C[2].B)); + if(tessFace->is_rgba) + tessFace->rgba_vertices.push_back(byte(C[2].A)); + + tess->addTessFace(tessFace); + const uint32_t tess_index = add3DTess(tess); + PRCPolyBrepModel *polyBrepModel = new PRCPolyBrepModel(); + polyBrepModel->index_tessellation = tess_index; + polyBrepModel->is_closed = group.options.closed; + group.polymodels.push_back(polyBrepModel); +} + +void oPRCFile::addLines(uint32_t nP, const double P[][3], uint32_t nI, const uint32_t PI[], + const RGBAColour &c, double w, bool segment_color, + uint32_t nC, const RGBAColour C[], uint32_t nCI, const uint32_t CI[]) +{ + if(nP==0 || P==NULL || nI==0 || PI==NULL) + return; + + const bool vertex_color = (nC != 0 && C != NULL && CI != NULL); + + PRCgroup &group = findGroup(); + PRC3DWireTess *tess = new PRC3DWireTess(); + for(uint32_t i=0; i<nP; i++) + { + tess->coordinates.push_back(P[i][0]); + tess->coordinates.push_back(P[i][1]); + tess->coordinates.push_back(P[i][2]); + } + for(uint32_t i=0; i<nI;) + { + tess->wire_indexes.push_back(PI[i]); + const uint32_t ni = i+PI[i]+1; + for(i++; i<ni; i++) + tess->wire_indexes.push_back(3*PI[i]); + } + if(vertex_color) + { + tess->is_segment_color = segment_color; + tess->is_rgba=false; + for(uint32_t i=0; i<nCI; i++) + if(1.0 != C[CI[i]].A) + { + tess->is_rgba=true; + break; + } + + for(uint32_t i=0; i<nCI; i++) + { + tess->rgba_vertices.push_back(byte(C[CI[i]].R)); + tess->rgba_vertices.push_back(byte(C[CI[i]].G)); + tess->rgba_vertices.push_back(byte(C[CI[i]].B)); + if(tess->is_rgba) + tess->rgba_vertices.push_back(byte(C[CI[i]].A)); + } + } + const uint32_t tess_index = add3DWireTess(tess); + PRCPolyWire *polyWire = new PRCPolyWire(); + polyWire->index_tessellation = tess_index; + if(vertex_color) + polyWire->index_of_line_style = addColourWidth(RGBAColour(1,1,1),w); + else + polyWire->index_of_line_style = addColourWidth(c,w); + group.polywires.push_back(polyWire); +} + +void oPRCFile::addLine(uint32_t n, const double P[][3], const RGBAColour &c, double w) { PRCgroup &group = findGroup(); if(group.options.tess) { - group.lines.push_back(PRCtessline()); - group.lines.back().color.red = c.R; - group.lines.back().color.green = c.G; - group.lines.back().color.blue = c.B; + group.lines[w].push_back(PRCtessline()); + PRCtessline& line = group.lines[w].back(); + line.color.red = c.R; + line.color.green = c.G; + line.color.blue = c.B; for(uint32_t i=0; i<n; i++) - group.lines.back().point.push_back(PRCVector3d(P[i][0],P[i][1],P[i][2])); + line.point.push_back(PRCVector3d(P[i][0],P[i][1],P[i][2])); } else { @@ -1174,7 +1619,7 @@ void oPRCFile::addBezierCurve(uint32_t n, const double cP[][3], void oPRCFile::addCurve(uint32_t d, uint32_t n, const double cP[][3], const double *k, const RGBAColour &c, const double w[]) { ADDWIRE(PRCNURBSCurve) - curve->is_rational = w; + curve->is_rational = (w!=NULL); curve->degree = d; curve->control_point.resize(n); for(uint32_t i = 0; i < n; i++) @@ -1245,7 +1690,7 @@ void oPRCFile::addPatch(const double cP[][3], const PRCmaterial &m) if(group.options.compression == 0.0) { ADDFACE(PRCNURBSSurface) - + surface->is_rational = false; surface->degree_in_u = 3; surface->degree_in_v = 3; @@ -1289,7 +1734,7 @@ void oPRCFile::addSurface(uint32_t dU, uint32_t dV, uint32_t nU, uint32_t nV, { ADDFACE(PRCNURBSSurface) - surface->is_rational = w; + surface->is_rational = (w!=NULL); surface->degree_in_u = dU; surface->degree_in_v = dV; surface->control_point.resize(nU*nV); @@ -1436,6 +1881,18 @@ void oPRCFile::addCylinder(double radius, double height, const PRCmaterial &m, P surface->radius = radius; } +void oPRCFile::addCone(double radius, double height, const PRCmaterial &m, PRCFACETRANSFORM) +{ + ADDFACE(PRCCone) + SETTRANSF + surface->uv_domain.min.x = 0; + surface->uv_domain.max.x = 2*pi; + surface->uv_domain.min.y = (height>0)?0:height; + surface->uv_domain.max.y = (height>0)?height:0; + surface->bottom_radius = radius; + surface->semi_angle = -atan(radius/height);; +} + void oPRCFile::addTorus(double major_radius, double minor_radius, double angle1, double angle2, const PRCmaterial &m, PRCFACETRANSFORM) { ADDFACE(PRCTorus) @@ -1455,37 +1912,37 @@ void oPRCFile::addTorus(double major_radius, double minor_radius, double angle1, uint32_t PRCFileStructure::addMaterialGeneric(PRCMaterialGeneric*& pMaterialGeneric) { - globals.materials.push_back(pMaterialGeneric); + materials.push_back(pMaterialGeneric); pMaterialGeneric = NULL; - return globals.materials.size()-1; + return materials.size()-1; } uint32_t PRCFileStructure::addTextureApplication(PRCTextureApplication*& pTextureApplication) { - globals.materials.push_back(pTextureApplication); + materials.push_back(pTextureApplication); pTextureApplication = NULL; - return globals.materials.size()-1; + return materials.size()-1; } uint32_t PRCFileStructure::addStyle(PRCStyle*& pStyle) { - globals.styles.push_back(pStyle); + styles.push_back(pStyle); pStyle = NULL; - return globals.styles.size()-1; + return styles.size()-1; } uint32_t PRCFileStructure::addPartDefinition(PRCPartDefinition*& pPartDefinition) { - tree.part_definitions.push_back(pPartDefinition); - pPartDefinition = NULL; - return tree.part_definitions.size()-1; + part_definitions.push_back(pPartDefinition); + pPartDefinition = NULL; + return part_definitions.size()-1; } uint32_t PRCFileStructure::addProductOccurrence(PRCProductOccurrence*& pProductOccurrence) { - tree.product_occurrences.push_back(pProductOccurrence); + product_occurrences.push_back(pProductOccurrence); pProductOccurrence = NULL; - return tree.product_occurrences.size()-1; + return product_occurrences.size()-1; } uint32_t PRCFileStructure::addTopoContext(PRCTopoContext*& pTopoContext) @@ -1504,56 +1961,56 @@ uint32_t PRCFileStructure::getTopoContext(PRCTopoContext*& pTopoContext) uint32_t PRCFileStructure::add3DTess(PRC3DTess*& p3DTess) { - tessellations.tessellations.push_back(p3DTess); + tessellations.push_back(p3DTess); p3DTess = NULL; - return tessellations.tessellations.size()-1; + return tessellations.size()-1; } uint32_t PRCFileStructure::add3DWireTess(PRC3DWireTess*& p3DWireTess) { - tessellations.tessellations.push_back(p3DWireTess); + tessellations.push_back(p3DWireTess); p3DWireTess = NULL; - return tessellations.tessellations.size()-1; + return tessellations.size()-1; } /* uint32_t PRCFileStructure::addMarkupTess(PRCMarkupTess*& pMarkupTess) { - tessellations.tessellations.push_back(pMarkupTess); + tessellations.push_back(pMarkupTess); pMarkupTess = NULL; - return tessellations.tessellations.size()-1; + return tessellations.size()-1; } uint32_t PRCFileStructure::addMarkup(PRCMarkup*& pMarkup) { - tree.markups.push_back(pMarkup); + markups.push_back(pMarkup); pMarkup = NULL; - return tree.markups.size()-1; + return markups.size()-1; } uint32_t PRCFileStructure::addAnnotationItem(PRCAnnotationItem*& pAnnotationItem) { - tree.annotation_entities.push_back(pAnnotationItem); + annotation_entities.push_back(pAnnotationItem); pAnnotationItem = NULL; - return tree.annotation_entities.size()-1; + return annotation_entities.size()-1; } */ uint32_t PRCFileStructure::addCoordinateSystem(PRCCoordinateSystem*& pCoordinateSystem) { - globals.reference_coordinate_systems.push_back(pCoordinateSystem); + reference_coordinate_systems.push_back(pCoordinateSystem); pCoordinateSystem = NULL; - return globals.reference_coordinate_systems.size()-1; + return reference_coordinate_systems.size()-1; } uint32_t PRCFileStructure::addCoordinateSystemUnique(PRCCoordinateSystem*& pCoordinateSystem) { - for(uint32_t i = 0; i < globals.reference_coordinate_systems.size(); ++i) + for(uint32_t i = 0; i < reference_coordinate_systems.size(); ++i) { - if(*(globals.reference_coordinate_systems[i])==*pCoordinateSystem) { + if(*(reference_coordinate_systems[i])==*pCoordinateSystem) { pCoordinateSystem = NULL; return i; } } - globals.reference_coordinate_systems.push_back(pCoordinateSystem); + reference_coordinate_systems.push_back(pCoordinateSystem); pCoordinateSystem = NULL; - return globals.reference_coordinate_systems.size()-1; + return reference_coordinate_systems.size()-1; } diff --git a/Build/source/utils/asymptote/prc/oPRCFile.h b/Build/source/utils/asymptote/prc/oPRCFile.h index 48683bf36da..643a0ff6e44 100644 --- a/Build/source/utils/asymptote/prc/oPRCFile.h +++ b/Build/source/utils/asymptote/prc/oPRCFile.h @@ -66,21 +66,61 @@ struct RGBAColour } }; typedef std::map<RGBAColour,uint32_t> PRCcolourMap; + +struct RGBAColourWidth +{ + RGBAColourWidth(double r=0.0, double g=0.0, double b=0.0, double a=1.0, double w=1.0) : + R(r), G(g), B(b), A(a), W(w) {} + double R,G,B,A,W; + + bool operator==(const RGBAColourWidth &c) const + { + return (R==c.R && G==c.G && B==c.B && A==c.A && W==c.W); + } + bool operator!=(const RGBAColourWidth &c) const + { + return !(R==c.R && G==c.G && B==c.B && A==c.A && W==c.W); + } + bool operator<(const RGBAColourWidth &c) const + { + if(R!=c.R) + return (R<c.R); + if(G!=c.G) + return (G<c.G); + if(B!=c.B) + return (B<c.B); + if(A!=c.A) + return (A<c.A); + return (W<c.W); + } +}; +typedef std::map<RGBAColourWidth,uint32_t> PRCcolourwidthMap; + typedef std::map<PRCRgbColor,uint32_t> PRCcolorMap; struct PRCmaterial { - PRCmaterial() : alpha(1.0),shininess(1.0) {} + PRCmaterial() : alpha(1.0),shininess(1.0), + picture(NULL), picture_width(0), picture_height(0), picture_rgba(false), picture_replace(false) {} PRCmaterial(const RGBAColour &a, const RGBAColour &d, const RGBAColour &e, - const RGBAColour &s, double p, double h) : - ambient(a), diffuse(d), emissive(e), specular(s), alpha(p), shininess(h) {} + const RGBAColour &s, double p, double h, + const uint8_t* pic=NULL, uint32_t picw=0, uint32_t pich=0, bool pica=false, bool picr=false) : + ambient(a), diffuse(d), emissive(e), specular(s), alpha(p), shininess(h), + picture(pic), picture_width(picw), picture_height(pich), picture_rgba(pica), picture_replace(picr) {} RGBAColour ambient,diffuse,emissive,specular; double alpha,shininess; + const uint8_t* picture; + uint32_t picture_width; + uint32_t picture_height; + bool picture_rgba; // is there alpha component? + bool picture_replace; // replace material color with texture color? if false - just modify bool operator==(const PRCmaterial &m) const { return (ambient==m.ambient && diffuse==m.diffuse && emissive==m.emissive - && specular==m.specular && alpha==m.alpha && shininess==m.shininess); + && specular==m.specular && alpha==m.alpha && shininess==m.shininess + && picture==m.picture && picture_width==m.picture_width && picture_height==m.picture_height + && picture_rgba==m.picture_rgba && picture_replace==m.picture_replace); } bool operator<(const PRCmaterial &m) const { @@ -94,7 +134,17 @@ struct PRCmaterial return (specular<m.specular); if(alpha!=m.alpha) return (alpha<m.alpha); - return (shininess<m.shininess); + if(shininess!=m.shininess) + return (shininess<m.shininess); + if(picture!=m.picture) + return (picture<m.picture); + if(picture_width!=m.picture_width) + return (picture_width<m.picture_width); + if(picture_height!=m.picture_height) + return (picture_height<m.picture_height); + if(picture_rgba!=m.picture_rgba) + return (picture_rgba<m.picture_rgba); + return (picture_replace<m.picture_replace); } }; typedef std::map<PRCmaterial,uint32_t> PRCmaterialMap; @@ -106,12 +156,22 @@ struct PRCtessrectangle // rectangle }; typedef std::vector<PRCtessrectangle> PRCtessrectangleList; +struct PRCtesstriangles // triangle +{ + std::vector<PRCVector3d> vertices; + std::vector<PRCVector3d> normals; + std::vector<RGBAColour> colors; + uint32_t style; +}; +typedef std::vector<PRCtesstriangles> PRCtesstrianglesList; + struct PRCtessline // polyline { std::vector<PRCVector3d> point; PRCRgbColor color; }; typedef std::list<PRCtessline> PRCtesslineList; +typedef std::map<double, PRCtesslineList> PRCtesslineMap; struct PRCface { @@ -148,12 +208,12 @@ class PRCoptions public: double compression; double granularity; - - bool closed; // render the surface as one-sided; may yield faster rendering + + bool closed; // render the surface as one-sided; may yield faster rendering bool tess; // use tessellated mesh to store straight patches - bool do_break; // + bool do_break; // bool no_break; // do not render transparent patches as one-faced nodes - + PRCoptions(double compression=0.0, double granularity=0.0, bool closed=false, bool tess=false, bool do_break=true, bool no_break=false) : compression(compression), granularity(granularity), closed(closed), @@ -168,9 +228,12 @@ class PRCgroup PRCfaceList faces; PRCcompfaceList compfaces; PRCtessrectangleList rectangles; - PRCtesslineList lines; + PRCtesslineMap lines; PRCwireList wires; PRCpointsetMap points; + std::vector<PRCPointSet*> pointsets; + std::vector<PRCPolyBrepModel*> polymodels; + std::vector<PRCPolyWire*> polywires; std::string name; std::list<PRCgroup> groupList; PRCGeneralTransformation3d* transform; @@ -178,150 +241,8 @@ class PRCgroup }; typedef std::list<PRCgroup> PRCgroupList; -class PRCCompressedSection -{ - public: - PRCCompressedSection(oPRCFile *p) : data(0),prepared(false),parent(p),fileStructure(NULL), - out(data,0) {} - PRCCompressedSection(PRCFileStructure *fs) : data(0),prepared(false),parent(NULL),fileStructure(fs), - out(data,0) {} - virtual ~PRCCompressedSection() - { - free(data); - } - void write(std::ostream&); - void prepare(); - uint32_t getSize(); - - private: - virtual void writeData() = 0; - uint8_t *data; - protected: - void compress() - { - out.compress(); - } - bool prepared; - oPRCFile *parent; - PRCFileStructure *fileStructure; - PRCbitStream out; // order matters: PRCbitStream must be initialized last -}; - -class PRCGlobalsSection : public PRCCompressedSection -{ - public: - PRCGlobalsSection(PRCFileStructure *fs, uint32_t i) : - PRCCompressedSection(fs),numberOfReferencedFileStructures(0), - tessellationChordHeightRatio(2000.0),tessellationAngleDegrees(40.0), - defaultFontFamilyName(""), - numberOfFillPatterns(0), - userData(0,0),index(i) {} - virtual ~PRCGlobalsSection() { - for(PRCTextureDefinitionList::iterator i = texture_definitions.begin(); - i != texture_definitions.end(); i++) - delete *i; - for(PRCMaterialList::iterator i = materials.begin(); - i != materials.end(); i++) - delete *i; - for(PRCStyleList::iterator i = styles.begin(); - i != styles.end(); i++) - delete *i; - for(PRCCoordinateSystemList::iterator i = - reference_coordinate_systems.begin(); - i != reference_coordinate_systems.end(); i++) - delete *i; - } - uint32_t numberOfReferencedFileStructures; - double tessellationChordHeightRatio; - double tessellationAngleDegrees; - std::string defaultFontFamilyName; - std::vector<PRCRgbColor> colors; - std::vector<PRCPicture> pictures; - PRCTextureDefinitionList texture_definitions; - PRCMaterialList materials; - PRCStyleList styles; - uint32_t numberOfFillPatterns; - PRCCoordinateSystemList reference_coordinate_systems; - std::vector<PRCFontKeysSameFont> font_keys_of_font; - UserData userData; - private: - uint32_t index; - virtual void writeData(); -}; - -class PRCTreeSection : public PRCCompressedSection -{ - public: - PRCTreeSection(PRCFileStructure *fs, uint32_t i) : - PRCCompressedSection(fs),unit(1),index(i) {} - virtual ~PRCTreeSection() - { - for(PRCPartDefinitionList::iterator it=part_definitions.begin(); it!=part_definitions.end(); ++it) delete *it; - for(PRCProductOccurrenceList::iterator it=product_occurrences.begin(); it!=product_occurrences.end(); ++it) delete *it; - } - - PRCPartDefinitionList part_definitions; - PRCProductOccurrenceList product_occurrences; -/* - PRCMarkupList markups; - PRCAnnotationItemList annotation_entities; - */ - double unit; - private: - uint32_t index; - virtual void writeData(); -}; - -class PRCTessellationSection : public PRCCompressedSection -{ - public: - PRCTessellationSection(PRCFileStructure *fs, uint32_t i) : - PRCCompressedSection(fs),index(i) {} - virtual ~PRCTessellationSection() { - for(PRCTessList::iterator it=tessellations.begin(); - it!=tessellations.end(); ++it) - delete *it; - } - PRCTessList tessellations; - private: - uint32_t index; - virtual void writeData(); -}; - -class PRCGeometrySection : public PRCCompressedSection -{ - public: - PRCGeometrySection(PRCFileStructure *fs, uint32_t i) : - PRCCompressedSection(fs),index(i) {} - virtual ~PRCGeometrySection() {} - private: - uint32_t index; - virtual void writeData(); -}; - -class PRCExtraGeometrySection : public PRCCompressedSection -{ - public: - PRCExtraGeometrySection(PRCFileStructure *fs, uint32_t i) : - PRCCompressedSection(fs),index(i) {} - virtual ~PRCExtraGeometrySection() {} - private: - uint32_t index; - virtual void writeData(); -}; - -class PRCModelFile : public PRCCompressedSection -{ - public: - PRCModelFile(oPRCFile *p) : PRCCompressedSection(p), unit(1) {} - double unit; - virtual ~PRCModelFile() {} - private: - virtual void writeData(); -}; - -void makeFileUUID(uint32_t*); -void makeAppUUID(uint32_t*); +void makeFileUUID(PRCUniqueId&); +void makeAppUUID(PRCUniqueId&); class PRCUncompressedFile { @@ -334,54 +255,101 @@ class PRCUncompressedFile uint8_t *data; // std::string file_name; - void write(std::ostream&); + void write(std::ostream&) const; - uint32_t getSize(); + uint32_t getSize() const; }; +typedef std::deque <PRCUncompressedFile*> PRCUncompressedFileList; class PRCStartHeader { public: uint32_t minimal_version_for_read; // PRCVersion uint32_t authoring_version; // PRCVersion - uint32_t fileStructureUUID[4]; - uint32_t applicationUUID[4]; // should be 0 + PRCUniqueId file_structure_uuid; + PRCUniqueId application_uuid; // should be 0 - void write(std::ostream&); + PRCStartHeader() : + minimal_version_for_read(PRCVersion), authoring_version(PRCVersion) {} + void serializeStartHeader(std::ostream&) const; - uint32_t getSize(); + uint32_t getStartHeaderSize() const; }; -class PRCFileStructure +class PRCFileStructure : public PRCStartHeader { - private: - oPRCFile *parent; - uint32_t index; public: - PRCStartHeader header; - std::list<PRCUncompressedFile> uncompressedFiles; + uint32_t number_of_referenced_file_structures; + double tessellation_chord_height_ratio; + double tessellation_angle_degree; + std::string default_font_family_name; + std::vector<PRCRgbColor> colors; + std::vector<PRCPicture> pictures; + PRCUncompressedFileList uncompressed_files; + PRCTextureDefinitionList texture_definitions; + PRCMaterialList materials; + PRCStyleList styles; + PRCCoordinateSystemList reference_coordinate_systems; + std::vector<PRCFontKeysSameFont> font_keys_of_font; + PRCPartDefinitionList part_definitions; + PRCProductOccurrenceList product_occurrences; +// PRCMarkupList markups; +// PRCAnnotationItemList annotation_entities; + double unit; PRCTopoContextList contexts; + PRCTessList tessellations; + + uint32_t sizes[6]; + uint8_t *globals_data; + PRCbitStream globals_out; // order matters: PRCbitStream must be initialized last + uint8_t *tree_data; + PRCbitStream tree_out; + uint8_t *tessellations_data; + PRCbitStream tessellations_out; + uint8_t *geometry_data; + PRCbitStream geometry_out; + uint8_t *extraGeometry_data; + PRCbitStream extraGeometry_out; ~PRCFileStructure () { - for(PRCTopoContextList::iterator i = contexts.begin(); - i != contexts.end(); i++) - delete *i; + for(PRCUncompressedFileList::iterator it=uncompressed_files.begin(); it!=uncompressed_files.end(); ++it) delete *it; + for(PRCTextureDefinitionList::iterator it=texture_definitions.begin(); it!=texture_definitions.end(); ++it) delete *it; + for(PRCMaterialList::iterator it=materials.begin(); it!=materials.end(); ++it) delete *it; + for(PRCStyleList::iterator it=styles.begin(); it!=styles.end(); ++it) delete *it; + for(PRCTopoContextList::iterator it=contexts.begin(); it!=contexts.end(); ++it) delete *it; + for(PRCTessList::iterator it=tessellations.begin(); it!=tessellations.end(); ++it) delete *it; + for(PRCPartDefinitionList::iterator it=part_definitions.begin(); it!=part_definitions.end(); ++it) delete *it; + for(PRCProductOccurrenceList::iterator it=product_occurrences.begin(); it!=product_occurrences.end(); ++it) delete *it; + for(PRCCoordinateSystemList::iterator it=reference_coordinate_systems.begin(); it!=reference_coordinate_systems.end(); it++) + delete *it; + + free(globals_data); + free(tree_data); + free(tessellations_data); + free(geometry_data); + free(extraGeometry_data); } - - PRCGlobalsSection globals; - PRCTreeSection tree; - PRCTessellationSection tessellations; - PRCGeometrySection geometry; - PRCExtraGeometrySection extraGeometry; - - PRCFileStructure(oPRCFile *p, uint32_t i) : parent(p),index(i), - globals(this,i),tree(this,i),tessellations(this,i),geometry(this,i), - extraGeometry(this,i) {} + + PRCFileStructure() : + number_of_referenced_file_structures(0), + tessellation_chord_height_ratio(2000.0),tessellation_angle_degree(40.0), + default_font_family_name(""), + unit(1), + globals_data(NULL),globals_out(globals_data,0), + tree_data(NULL),tree_out(tree_data,0), + tessellations_data(NULL),tessellations_out(tessellations_data,0), + geometry_data(NULL),geometry_out(geometry_data,0), + extraGeometry_data(NULL),extraGeometry_out(extraGeometry_data,0) {} void write(std::ostream&); void prepare(); uint32_t getSize(); + void serializeFileStructureGlobals(PRCbitStream&); + void serializeFileStructureTree(PRCbitStream&); + void serializeFileStructureTessellation(PRCbitStream&); + void serializeFileStructureGeometry(PRCbitStream&); + void serializeFileStructureExtraGeometry(PRCbitStream&); uint32_t addPicture(EPRCPictureDataFormat format, uint32_t size, const uint8_t *picture, uint32_t width=0, uint32_t height=0, std::string name=""); - uint32_t addTextureDefinition(PRCTextureDefinition *pTextureDefinition); + uint32_t addTextureDefinition(PRCTextureDefinition*& pTextureDefinition); uint32_t addRgbColor(const PRCRgbColor &color); uint32_t addRgbColorUnique(const PRCRgbColor &color); uint32_t addMaterialGeneric(PRCMaterialGeneric*& pMaterialGeneric); @@ -405,7 +373,7 @@ class PRCFileStructure class PRCFileStructureInformation { public: - uint32_t UUID[4]; + PRCUniqueId UUID; uint32_t reserved; // 0 uint32_t number_of_offsets; uint32_t *offsets; @@ -415,15 +383,14 @@ class PRCFileStructureInformation uint32_t getSize(); }; -class PRCHeader +class PRCHeader : public PRCStartHeader { public : - PRCStartHeader startHeader; uint32_t number_of_file_structures; PRCFileStructureInformation *fileStructureInformation; uint32_t model_file_offset; uint32_t file_size; // not documented - std::list<PRCUncompressedFile> uncompressedFiles; + PRCUncompressedFileList uncompressed_files; void write(std::ostream&); uint32_t getSize(); @@ -434,40 +401,42 @@ typedef std::map <PRCGeneralTransformation3d,uint32_t> PRCtransformMap; class oPRCFile { public: - oPRCFile(std::ostream &os, double unit=1, uint32_t n=1) : + oPRCFile(std::ostream &os, double u=1, uint32_t n=1) : number_of_file_structures(n), - fileStructures(new PRCFileStructure*[n]),modelFile(this), + fileStructures(new PRCFileStructure*[n]), + unit(u), + modelFile_data(NULL),modelFile_out(modelFile_data,0), fout(NULL),output(os) { for(uint32_t i = 0; i < number_of_file_structures; ++i) { - fileStructures[i] = new PRCFileStructure(this,i); - fileStructures[i]->header.minimal_version_for_read = PRCVersion; - fileStructures[i]->header.authoring_version = PRCVersion; - makeFileUUID(fileStructures[i]->header.fileStructureUUID); - makeAppUUID(fileStructures[i]->header.applicationUUID); - fileStructures[i]->tree.unit = unit; + fileStructures[i] = new PRCFileStructure(); + fileStructures[i]->minimal_version_for_read = PRCVersion; + fileStructures[i]->authoring_version = PRCVersion; + makeFileUUID(fileStructures[i]->file_structure_uuid); + makeAppUUID(fileStructures[i]->application_uuid); + fileStructures[i]->unit = u; } - modelFile.unit = unit; } - - oPRCFile(const std::string &name, double unit=1, uint32_t n=1) : + + oPRCFile(const std::string &name, double u=1, uint32_t n=1) : number_of_file_structures(n), - fileStructures(new PRCFileStructure*[n]),modelFile(this), + fileStructures(new PRCFileStructure*[n]), + unit(u), + modelFile_data(NULL),modelFile_out(modelFile_data,0), fout(new std::ofstream(name.c_str(), std::ios::out|std::ios::binary|std::ios::trunc)), output(*fout) { for(uint32_t i = 0; i < number_of_file_structures; ++i) { - fileStructures[i] = new PRCFileStructure(this,i); - fileStructures[i]->header.minimal_version_for_read = PRCVersion; - fileStructures[i]->header.authoring_version = PRCVersion; - makeFileUUID(fileStructures[i]->header.fileStructureUUID); - makeAppUUID(fileStructures[i]->header.applicationUUID); - fileStructures[i]->tree.unit = unit; + fileStructures[i] = new PRCFileStructure(); + fileStructures[i]->minimal_version_for_read = PRCVersion; + fileStructures[i]->authoring_version = PRCVersion; + makeFileUUID(fileStructures[i]->file_structure_uuid); + makeAppUUID(fileStructures[i]->application_uuid); + fileStructures[i]->unit = u; } - modelFile.unit = unit; } ~oPRCFile() @@ -477,21 +446,25 @@ class oPRCFile delete[] fileStructures; if(fout != NULL) delete fout; + free(modelFile_data); } void begingroup(const char *name, PRCoptions *options=NULL, const double t[][4]=NULL); void endgroup(); - + bool finish(); uint32_t getSize(); - + const uint32_t number_of_file_structures; PRCFileStructure **fileStructures; PRCHeader header; - PRCModelFile modelFile; + PRCUnit unit; + uint8_t *modelFile_data; + PRCbitStream modelFile_out; // order matters: PRCbitStream must be initialized last PRCcolorMap colorMap; PRCcolourMap colourMap; + PRCcolourwidthMap colourwidthMap; PRCmaterialMap materialMap; PRCgroup rootGroup; PRCtransformMap transformMap; @@ -500,12 +473,29 @@ class oPRCFile void doGroup(PRCgroup& group, PRCPartDefinition *parent_part_definition, PRCProductOccurrence *parent_product_occurrence); uint32_t addColor(const PRCRgbColor &color); uint32_t addColour(const RGBAColour &colour); + uint32_t addColourWidth(const RGBAColour &colour, double width); uint32_t addMaterial(const PRCmaterial &material); uint32_t addTransform(PRCGeneralTransformation3d*& transform); - void addPoint(const double P[3], const RGBAColour &c); - void addLine(uint32_t n, const double P[][3], const RGBAColour &c); + void addPoint(const double P[3], const RGBAColour &c, double w=1.0); + void addPoints(uint32_t n, const double P[][3], const RGBAColour &c, double w=1.0); + void addLines(uint32_t nP, const double P[][3], uint32_t nI, const uint32_t PI[], + const RGBAColour &c, double w, bool segment_color, + uint32_t nC, const RGBAColour C[], uint32_t nCI, const uint32_t CI[]); + void addTriangles(uint32_t nP, const double P[][3], uint32_t nI, const uint32_t PI[][3], const PRCmaterial &m, + uint32_t nN, const double N[][3], const uint32_t NI[][3], + uint32_t nT, const double T[][2], const uint32_t TI[][3], + uint32_t nC, const RGBAColour C[], const uint32_t CI[][3], + uint32_t nM, const PRCmaterial M[], const uint32_t MI[]); + void addQuads(uint32_t nP, const double P[][3], uint32_t nI, const uint32_t PI[][4], const PRCmaterial &m, + uint32_t nN, const double N[][3], const uint32_t NI[][4], + uint32_t nT, const double T[][2], const uint32_t TI[][4], + uint32_t nC, const RGBAColour C[], const uint32_t CI[][4], + uint32_t nM, const PRCmaterial M[], const uint32_t MI[]); + void addLine(uint32_t n, const double P[][3], const RGBAColour &c, double w=1.0); void addBezierCurve(uint32_t n, const double cP[][3], const RGBAColour &c); void addCurve(uint32_t d, uint32_t n, const double cP[][3], const double *k, const RGBAColour &c, const double w[]); + void addQuad(const double P[][3], const RGBAColour C[]); + void addRectangle(const double P[][3], const PRCmaterial &m); void addPatch(const double cP[][3], const PRCmaterial &m); void addSurface(uint32_t dU, uint32_t dV, uint32_t nU, uint32_t nV, @@ -517,6 +507,7 @@ class oPRCFile void addSphere(double radius, const PRCmaterial &m, PRCFACETRANSFORM); void addDisk(double radius, const PRCmaterial &m, PRCFACETRANSFORM); void addCylinder(double radius, double height, const PRCmaterial &m, PRCFACETRANSFORM); + void addCone(double radius, double height, const PRCmaterial &m, PRCFACETRANSFORM); void addTorus(double major_radius, double minor_radius, double angle1, double angle2, const PRCmaterial &m, PRCFACETRANSFORM); #undef PRCFACETRANSFORM @@ -598,6 +589,7 @@ class oPRCFile return fileStructures[fileStructure]->addCoordinateSystemUnique(pCoordinateSystem); } private: + void serializeModelFileData(PRCbitStream&); std::ofstream *fout; std::ostream &output; }; diff --git a/Build/source/utils/asymptote/prc/test.cc b/Build/source/utils/asymptote/prc/test.cc index 98a6c226c43..61577a1ff77 100644 --- a/Build/source/utils/asymptote/prc/test.cc +++ b/Build/source/utils/asymptote/prc/test.cc @@ -31,6 +31,13 @@ extern const double pi; int main() { + // List of pictures used; keep track of memory allocated to free it in the end + // shared pointers or garbage collector may be an alternative + uint8_t *picture1 = NULL; + uint8_t *picture2 = NULL; + uint8_t *picture3 = NULL; + uint8_t *picture4 = NULL; + oPRCFile file("test.prc"); const size_t N_COLOURS = 32; @@ -265,35 +272,33 @@ int main() {0,-1.5,0.15},{0.84,-1.5,0.15},{1.5,-0.84,0.15},{1.5,0,0.15}, }, }; - const size_t NUMBER_OF_TEAPOTS = 2; - double shifted_controlPoints[NUMBER_OF_TEAPOTS][NUMBER_OF_PATCHES][16][3]; - for(size_t teapot = 0; teapot < NUMBER_OF_TEAPOTS; ++teapot) - for(size_t patch = 0; patch < NUMBER_OF_PATCHES; ++patch) - for(size_t i = 0; i < 16; ++i) - { - shifted_controlPoints[teapot][patch][i][0] = controlPoints[patch][i][0]+6*teapot; - shifted_controlPoints[teapot][patch][i][1] = controlPoints[patch][i][1]; - shifted_controlPoints[teapot][patch][i][2] = controlPoints[patch][i][2]; - } + file.begingroup("Teapot"); for(size_t i = 0; i < NUMBER_OF_PATCHES; ++i) { - // was so in old API - // psn[i] = new PRCsurface(&file,3,3,4,4,controlPoints[i],knotsU,knotsV,colours[i%N_COLOURS]); - // file.add(psn[i]); - file.begingroup("Teapot"); - if (1) file.addPatch(controlPoints[i],materials[i%N_COLOURS]); - file.endgroup(); - if (0) file.addSurface(3,3,4,4,controlPoints[i],knotsU,knotsV,materials[i%N_COLOURS],NULL); // use (too) general API for the same result as above + if(1) file.addPatch(controlPoints[i],materials[i%N_COLOURS]); + if(0) file.addSurface(3,3,4,4,controlPoints[i],knotsU,knotsV,materials[i%N_COLOURS],NULL); // use (too) general API for the same result as above } -// file.begingroup("Teapot rendered in the way of opaque surfacesPRCNOBREAKPRCCOMPRESSLOW"); -// for(size_t i = 0; i < NUMBER_OF_PATCHES; ++i) -// { -// file.addPatch(shifted_controlPoints[1][i],materials[i%N_COLOURS]); // force joining together of patches, damaging transparency -// } -// file.endgroup(); + file.endgroup(); + + double t[4][4]; + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=6; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=0; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + + PRCoptions teapotopt; + teapotopt.no_break = true; + teapotopt.do_break = false; + teapotopt.compression = 0.0001; + // force joining together of patches, damaging transparency + file.begingroup("Teapot rendered in the way of opaque surfaces and transferred",&teapotopt,t); + for(size_t i = 0; i < NUMBER_OF_PATCHES; ++i) + { + file.addPatch(controlPoints[i],materials[i%N_COLOURS]); + } + file.endgroup(); } - -if(1) { + const size_t NUMBER_OF_POINTS = 31; double points[NUMBER_OF_POINTS][3]; for(size_t i = 0; i < NUMBER_OF_POINTS; ++i) @@ -319,47 +324,425 @@ if(1) { } knots[3+NUMBER_OF_POINTS] = (3+NUMBER_OF_POINTS+1)/3; - double point[3] = {11,0,0}; - file.begingroup("point"); - file.addPoint(point, RGBAColour(1.0,0.0,0.0)); - file.endgroup(); - -// RGBAColour red(1.0,0.0,0.0); -// PRCline pl(&file,NUMBER_OF_POINTS,points,red); -// file.add(&pl); - file.begingroup("polyline"); - file.addLine(NUMBER_OF_POINTS, points, RGBAColour(1.0,0.0,0.0)); - file.endgroup(); - - file.begingroup("polylines"); - file.addLine(NUMBER_OF_POINTS, shifted_points[0], RGBAColour(0.0,1.0,0.0)); - file.addLine(NUMBER_OF_POINTS, shifted_points[1], RGBAColour(1.0,1.0,0.0)); - file.endgroup(); - -// RGBAColour white(1.0,1.0,1.0); -// PRCcurve pc(&file,3,NUMBER_OF_POINTS,points,knots,white); -// file.add(&pc); + PRCoptions grpopt; + grpopt.no_break = true; + grpopt.do_break = false; + grpopt.tess = true; + if(1){ + double point1[3] = {11,0,0}; + double point2[3] = {12,0,0}; + double points[2][3] = {{9,0,0},{10,0,0}}; + file.begingroup("points",&grpopt); + file.addPoint(point1, RGBAColour(1.0,0.0,0.0)); + file.addPoint(point2, RGBAColour(1.0,0.0,0.0)); + file.addPoints(2, points, RGBAColour(1.0,0.0,0.0,0.5),10); + file.endgroup(); + } + + if(1){ + PRCoptions grpopt; + grpopt.no_break = true; + grpopt.do_break = false; + grpopt.tess = true; + grpopt.closed = true; + + double t[4][4]; + + const size_t nP = 5; + double P[nP][3] = {{0,0,0},{1,0,0},{1,1,0},{0,1,0},{0,2,0}}; + const size_t nI = 3; + uint32_t PI[nI][3] = {{0,1,3},{1,2,3},{3,2,4}}; + const size_t nM = 2; + PRCmaterial M[nM]; + M[0] = PRCmaterial( + RGBAColour(0.0,0.0,0.18), + RGBAColour(0.0,0.0,0.878431), + RGBAColour(0.0,0.0,0.32), + RGBAColour(0.0,0.0,0.072), + 1.0,0.1); + M[1] = PRCmaterial( + RGBAColour(0.18,0.0,0.0), + RGBAColour(0.878431,0.0,0.0), + RGBAColour(0.32,0.0,0.0), + RGBAColour(0.072,0.0,0.0), + 0.5,0.1); + uint32_t MI[nI] = {0,1,0}; + const size_t nN = 2; + double N[nN][3] = {{0,0,1},{0,0,-1}}; + uint32_t NI[nI][3] = {{0,0,0},{0,0,0},{1,1,1}}; + + const uint32_t nC = 3; + RGBAColour C[nC]; + uint32_t CI[nI][3] = {{0,0,0},{1,1,1},{1,1,2}}; + + PRCmaterial materialGreen( + RGBAColour(0.0,0.18,0.0), + RGBAColour(0.0,0.878431,0.0), + RGBAColour(0.0,0.32,0.0), + RGBAColour(0.0,0.072,0.0), + 1.0,0.1); + + if(1){ + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=-1; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + file.begingroup("triangles_onecolor_with_normals",&grpopt,t); + file.addTriangles(nP, P, nI, PI, materialGreen, nN, N, NI, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL); + file.endgroup(); + } + + if(1){ + file.begingroup("triangles_onecolor",&grpopt); + file.addTriangles(nP, P, nI, PI, materialGreen, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL); + file.endgroup(); + } + + if(1){ + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=1; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + file.begingroup("triangles_manymaterials",&grpopt,t); + file.addTriangles(nP, P, nI, PI, materialGreen, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, nM, M, MI); + file.endgroup(); + } + + if(1){ + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=2; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + PRCmaterial materialBase( + RGBAColour(0.1,0.1,0.1,1), + RGBAColour(1,1,1,1), + RGBAColour(0.1,0.1,0.1,1), + RGBAColour(0.1,0.1,0.1,1), + 1.0,0.1); + C[0] = RGBAColour(1,0,0,0.1); + C[1] = RGBAColour(0,1,0,0.5); + C[2] = RGBAColour(0,0,1,0.9); + file.begingroup("triangles_rgba_vertexcolors_on_opaque_a_component_of_vertexcolor_ignored",&grpopt,t); + file.addTriangles(nP, P, nI, PI, materialBase, 0, NULL, NULL, 0, NULL, NULL, nC, C, CI, 0, NULL, NULL); + file.endgroup(); + + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=3; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + PRCmaterial materialTransparent( + RGBAColour(0.1,0.1,0.1,0.3), + RGBAColour(1,1,1,0.3), + RGBAColour(0.1,0.1,0.1,0.3), + RGBAColour(0.1,0.1,0.1,0.3), + 0.3,0.1); + C[0] = RGBAColour(1,0,0,0.1); + C[1] = RGBAColour(0,1,0,0.5); + C[2] = RGBAColour(0,0,1,0.9); + file.begingroup("triangles_rgba_vertexcolors_on_transparent_a_component_of_vertexcolor_ignored",&grpopt,t); + file.addTriangles(nP, P, nI, PI, materialTransparent, 0, NULL, NULL, 0, NULL, NULL, nC, C, CI, 0, NULL, NULL); + file.endgroup(); + + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=4; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + C[0] = RGBAColour(1,0,0,0.5); + C[1] = RGBAColour(0,1,0,0.5); + C[2] = RGBAColour(0,0,1,0.5); + file.begingroup("triangles_rgb_vertexcolors_on_transparent_may_not_work_in_OpenGL",&grpopt,t); + file.addTriangles(nP, P, nI, PI, materialTransparent, 0, NULL, NULL, 0, NULL, NULL, nC, C, CI, 0, NULL, NULL); + file.endgroup(); + } + + if(1){ + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=5; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + const uint32_t picture_width=2; + const uint32_t picture_height=2; + const uint8_t picRGB[picture_width*picture_height*3] = + {255,0,0, 0,255,0, 0,0,255, 0,0,0 }; +// {255,255,0, 255,0,0, 255,0,0, 255,0,0 }; +// { 255,0,0, 255,255,0, 255,255,0, 255,255,255 }; +// {255,0,0, 0,255,0, 0,0,255, 0,0,0 }; + + const uint8_t picRGBA[picture_width*picture_height*4] = + {255,0,0,255, 0,255,0,150, 0,0,255,150, 0,0,0,100 }; +// (1,0) 2 3 (1,1) +// (0,0) 0 1 (1,0) + uint8_t *pictureRGB = new uint8_t[picture_width*picture_height*3]; + for(size_t i=0; i<picture_width*picture_height*3; i++) pictureRGB[i]=picRGB[i]; + picture1 = pictureRGB; + uint8_t *pictureRGBA = new uint8_t[picture_width*picture_height*4]; + for(size_t i=0; i<picture_width*picture_height*4; i++) pictureRGBA[i]=picRGBA[i]; + picture2 = pictureRGBA; + const uint32_t nT = 4; + const double T[nT][2] = { {0.1,0.1}, {0.9,0.1}, {0.9,0.9}, {0.9,0.1} }; + uint32_t TI[nI][3] = {{0,1,3},{1,2,3},{3,2,3}}; + + PRCmaterial materialBase( + RGBAColour(0.1,0.1,0.1,1), + RGBAColour(1,1,1,1), + RGBAColour(0.1,0.1,0.1,1), + RGBAColour(0.1,0.1,0.1,1), + 1.0,0.1, + pictureRGB, picture_width, picture_height, false, false); + file.begingroup("triangles_rgb_texture",&grpopt,t); + file.addTriangles(nP, P, nI, PI, materialBase, 0, NULL, NULL, nT, T, TI, 0, NULL, NULL, 0, NULL, NULL); + file.endgroup(); + + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=6; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + PRCmaterial materialTransparent( + RGBAColour(0.1,0.1,0.1,0.3), + RGBAColour(1,1,1,0.3), + RGBAColour(0.1,0.1,0.1,0.3), + RGBAColour(0.1,0.1,0.1,0.3), + 0.3,0.1, + pictureRGBA, picture_width, picture_height, true, true); + file.begingroup("triangles_rgba_texture_replacing",&grpopt,t); + file.addTriangles(nP, P, nI, PI, materialTransparent, 0, NULL, NULL, nT, T, TI, 0, NULL, NULL, 0, NULL, NULL); + file.endgroup(); + } + + } + + if(1){ + PRCoptions grpopt; + grpopt.no_break = true; + grpopt.do_break = false; + grpopt.tess = true; + grpopt.closed = true; + + double t[4][4]; + + const size_t nP = 6; + double P[nP][3] = {{3+0,0,0},{3+1,0,0},{3+0,1,0},{3+1,1,0},{3+0,2,0},{3+1,2,0}}; + const size_t nI = 2; + uint32_t PI[nI][4] = {{0,1,3,2},{2,3,5,4}}; + const size_t nM = 2; + PRCmaterial M[nM]; + M[0] = PRCmaterial( + RGBAColour(0.0,0.0,0.18), + RGBAColour(0.0,0.0,0.878431), + RGBAColour(0.0,0.0,0.32), + RGBAColour(0.0,0.0,0.072), + 1.0,0.1); + M[1] = PRCmaterial( + RGBAColour(0.18,0.0,0.0), + RGBAColour(0.878431,0.0,0.0), + RGBAColour(0.32,0.0,0.0), + RGBAColour(0.072,0.0,0.0), + 0.5,0.1); + uint32_t MI[nI] = {0,1}; + const size_t nN = 2; + double N[nN][3] = {{0,0,1},{0,0,-1}}; + uint32_t NI[nI][4] = {{0,0,0,0},{1,1,1,1}}; + + const uint32_t nC = 3; + RGBAColour C[nC]; + uint32_t CI[nI][4] = {{0,0,1,1},{1,1,2,2}}; + C[0] = RGBAColour(1,0,0,0.5); + C[1] = RGBAColour(0,1,0,0.5); + C[2] = RGBAColour(0,0,1,0.5); + + PRCmaterial materialGreen( + RGBAColour(0.0,0.18,0.0), + RGBAColour(0.0,0.878431,0.0), + RGBAColour(0.0,0.32,0.0), + RGBAColour(0.0,0.072,0.0), + 1.0,0.1); + + PRCmaterial materialBase( + RGBAColour(0.1,0.1,0.1,1), + RGBAColour(1,1,1,1), + RGBAColour(0.1,0.1,0.1,1), + RGBAColour(0.1,0.1,0.1,1), + 1.0,0.1); + + PRCmaterial materialTransparent( + RGBAColour(0.1,0.1,0.1,0.3), + RGBAColour(1,1,1,0.3), + RGBAColour(0.1,0.1,0.1,0.3), + RGBAColour(0.1,0.1,0.1,0.3), + 0.3,0.1); + + if(1){ + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=-1; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + file.begingroup("quads_onecolor_with_normals",&grpopt,t); + file.addQuads(nP, P, nI, PI, materialGreen, nN, N, NI, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL); + file.endgroup(); + } + + if(1){ + file.begingroup("quads_onecolor",&grpopt); + file.addQuads(nP, P, nI, PI, materialGreen, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL); + file.endgroup(); + } + + if(1){ + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=1; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + file.begingroup("quads_manymaterials",&grpopt,t); + file.addQuads(nP, P, nI, PI, materialGreen, 0, NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, nM, M, MI); + file.endgroup(); + } + + if(1){ + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=2; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + file.begingroup("quads_rgb_vertexcolors_on_transparent_may_not_work_in_OpenGL",&grpopt,t); + file.addQuads(nP, P, nI, PI, materialTransparent, 0, NULL, NULL, 0, NULL, NULL, nC, C, CI, 0, NULL, NULL); + file.endgroup(); + } + + if(1){ + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=5; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + const uint32_t picture_width=2; + const uint32_t picture_height=2; + const uint8_t picRGB[picture_width*picture_height*3] = + {255,0,0, 0,255,0, 0,0,255, 0,0,0 }; +// {255,255,0, 255,0,0, 255,0,0, 255,0,0 }; +// { 255,0,0, 255,255,0, 255,255,0, 255,255,255 }; +// {255,0,0, 0,255,0, 0,0,255, 0,0,0 }; + + const uint8_t picRGBA[picture_width*picture_height*4] = + {255,0,0,255, 0,255,0,150, 0,0,255,150, 0,0,0,100 }; +// (1,0) 2 3 (1,1) +// (0,0) 0 1 (1,0) + uint8_t *pictureRGB = new uint8_t[picture_width*picture_height*3]; + for(size_t i=0; i<picture_width*picture_height*3; i++) pictureRGB[i]=picRGB[i]; + picture3 = pictureRGB; + uint8_t *pictureRGBA = new uint8_t[picture_width*picture_height*4]; + for(size_t i=0; i<picture_width*picture_height*4; i++) pictureRGBA[i]=picRGBA[i]; + picture4 = pictureRGBA; + const uint32_t nT = 3; + const double T[nT][2] = { {0.1,0.1}, {0.5,0.5}, {0.9,0.9} }; + uint32_t TI[nI][4] = {{0,0,1,1},{1,1,2,2}}; + + PRCmaterial materialBase( + RGBAColour(0.1,0.1,0.1,1), + RGBAColour(1,1,1,1), + RGBAColour(0.1,0.1,0.1,1), + RGBAColour(0.1,0.1,0.1,1), + 1.0,0.1, + pictureRGB, picture_width, picture_height, false, false); + file.begingroup("quads_rgb_texture",&grpopt,t); + file.addQuads(nP, P, nI, PI, materialBase, 0, NULL, NULL, nT, T, TI, 0, NULL, NULL, 0, NULL, NULL); + file.endgroup(); + + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=6; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + PRCmaterial materialTransparent( + RGBAColour(0.1,0.1,0.1,0.3), + RGBAColour(1,1,1,0.3), + RGBAColour(0.1,0.1,0.1,0.3), + RGBAColour(0.1,0.1,0.1,0.3), + 0.6,0.1, + pictureRGBA, picture_width, picture_height, true, true); + file.begingroup("quads_rgba_texture_replacing",&grpopt,t); + file.addQuads(nP, P, nI, PI, materialTransparent, 0, NULL, NULL, nT, T, TI, 0, NULL, NULL, 0, NULL, NULL); + file.endgroup(); + } + + } + + if(1){ + file.begingroup("polyline",&grpopt); + file.addLine(NUMBER_OF_POINTS, points, RGBAColour(1.0,0.0,0.0)); + file.endgroup(); + + file.begingroup("polylines",&grpopt); + file.addLine(NUMBER_OF_POINTS, shifted_points[0], RGBAColour(0.0,1.0,0.0),2.0); + file.addLine(NUMBER_OF_POINTS, shifted_points[1], RGBAColour(1.0,1.0,0.0),2.0); + file.endgroup(); + } + + if(1){ + PRCoptions grpopt; + grpopt.no_break = true; + grpopt.do_break = false; + grpopt.tess = true; + grpopt.closed = true; + + double t[4][4]; + + const size_t nP = 5; + double P[nP][3] = {{0,0,0},{1,0,0},{1,1,0},{0,1,0},{0,2,0}}; + const size_t nI = 1+5 + 1+3; + uint32_t PI[nI] = {5,0,1,2,3,0, 3,2,4,3 }; // square of 5 points, wire of 2 points + const uint32_t nC = 5; // number of colors + RGBAColour C[nC]; // color for segments + C[0] = RGBAColour(1,0,0); + C[1] = RGBAColour(0,1,0); + C[2] = RGBAColour(0,0,1); + C[3] = RGBAColour(0,0,0); + C[4] = RGBAColour(1,1,0); + const uint32_t nCI = 5-1 + 3-1; // number of segments + uint32_t CI[nCI] = { 0,1,2,3, 4,4 }; + + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=5; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + file.begingroup("polyline_indexed_one_color",&grpopt,t); + file.addLines(nP, P, nI, PI, RGBAColour(1,0,0), 1, false, 0, NULL, 0, NULL); + file.endgroup(); + + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=6; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + file.begingroup("polyline_indexed_color_per_segment",&grpopt,t); + file.addLines(nP, P, nI, PI, RGBAColour(1,0,0), 2, true, nC, C, nCI, CI); + file.endgroup(); + + t[0][0]=1; t[0][1]=0; t[0][2]=0; t[0][3]=0; + t[1][0]=0; t[1][1]=1; t[1][2]=0; t[1][3]=0; + t[2][0]=0; t[2][1]=0; t[2][2]=1; t[2][3]=7; + t[3][0]=0; t[3][1]=0; t[3][2]=0; t[3][3]=1; + const uint32_t nCI2 = 5 + 3; // number of vertices + uint32_t CI2[nCI2] = { 0,1,2,3,0, 4,4,4 }; + file.begingroup("polyline_indexed_color_per_vertex_is_broken",&grpopt,t); + file.addLines(nP, P, nI, PI, RGBAColour(1,0,0), 2, false, nC, C, nCI2, CI2); + file.endgroup(); + } + if(1) { file.begingroup("bezier_wire"); file.addBezierCurve(NUMBER_OF_POINTS,points,RGBAColour(1.0,1.0,1.0)); file.endgroup(); } - if(0) + if(1) { file.begingroup("NURBS_wire"); file.addCurve(3, NUMBER_OF_POINTS, points, knots, RGBAColour(1.0,1.0,1.0), NULL); // genarl API for the above file.endgroup(); } - } - // following box examples show a) different ways to represent a surface consisting of flat rectangles // b) that the only way to have almost working transparency is a set of NURBS bodies. // (Or may be other topology types like plane also work // demonstration how non-transparent materials work the same for all kinds of objects - if (1) { // demonstration how non-transparent materials work the same for all kinds of objects + if(1) { // demonstration how non-transparent materials work the same for all kinds of objects const size_t NUMBER_OF_PATCHES = 6; double vertices[NUMBER_OF_PATCHES][4][3] = { @@ -417,20 +800,30 @@ if(1) { RGBAColour(0.0,0.072,0.0), 1.0,0.1); + PRCoptions grpopt; file.begingroup("TransparentBox"); - file.begingroup("SetOfNURBSBodies"); + grpopt.no_break = false; + grpopt.do_break = true; + grpopt.tess = false; + file.begingroup("TransparentBoxSetOfNURBSBodies",&grpopt); for(size_t patch = 0; patch < NUMBER_OF_PATCHES; ++patch) { file.addRectangle(shifted_vertices[0][patch], materials[(patch*5)%N_COLOURS]); } file.endgroup(); - file.begingroup("NURBSFacesPRCNOBREAK"); + grpopt.no_break = true; + grpopt.do_break = false; + grpopt.tess = false; + file.begingroup("TransparentBoxNURBSFaces",&grpopt); for(size_t patch = 0; patch < NUMBER_OF_PATCHES; ++patch) { file.addRectangle(shifted_vertices[1][patch], materials[(patch*5)%N_COLOURS]); } file.endgroup(); - file.begingroup("TessellatedPRCTESS"); + grpopt.no_break = true; + grpopt.do_break = false; + grpopt.tess = true; + file.begingroup("TransparentBoxTessellated",&grpopt); for(size_t patch = 0; patch < NUMBER_OF_PATCHES; ++patch) { file.addRectangle(shifted_vertices[2][patch], materials[(patch*5)%N_COLOURS]); @@ -439,19 +832,28 @@ if(1) { file.endgroup(); file.begingroup("Box"); - file.begingroup("TessellatedPRCTESS"); + grpopt.no_break = false; + grpopt.do_break = false; + grpopt.tess = true; + file.begingroup("BoxTessellated",&grpopt); for(size_t patch = 0; patch < NUMBER_OF_PATCHES; ++patch) { file.addRectangle(shifted_vertices[3][patch], materialGreen); } file.endgroup(); - file.begingroup("NURBSFaces"); + grpopt.no_break = true; + grpopt.do_break = false; + grpopt.tess = false; + file.begingroup("BoxNURBSFaces",&grpopt); for(size_t patch = 0; patch < NUMBER_OF_PATCHES; ++patch) { file.addRectangle(shifted_vertices[4][patch], materialGreen); } file.endgroup(); - file.begingroup("SetOfNURBSBodiesPRCDOBREAK"); + grpopt.no_break = false; + grpopt.do_break = true; + grpopt.tess = false; + file.begingroup("BoxSetOfNURBSBodies",&grpopt); for(size_t patch = 0; patch < NUMBER_OF_PATCHES; ++patch) { file.addRectangle(shifted_vertices[5][patch], materialGreen); @@ -460,62 +862,6 @@ if(1) { file.endgroup(); } - if(0) { // test disk - PRCTopoContext *diskContext = new PRCTopoContext; - uint32_t context_index = file.addTopoContext(diskContext); - - PRCBrepData *body = new PRCBrepData; - uint32_t body_index = diskContext->addBrepData(body); - PRCConnex *connex = new PRCConnex; - body->addConnex(connex); - PRCShell *shell = new PRCShell; - // shell->shell_is_closed = true; - connex->addShell(shell); - PRCFace *face = new PRCFace; - shell->addFace(face,2); - PRCRuled *surface = new PRCRuled; - face->base_surface=surface; - - PRCCircle *first_curve = new PRCCircle; - first_curve->radius = 1; - surface->first_curve=first_curve; - PRCCircle *second_curve = new PRCCircle; - second_curve->radius = 0; - surface->second_curve=second_curve; - - surface->uv_domain.min.x = 0; - surface->uv_domain.max.x = 1; - surface->uv_domain.min.y = 0; - surface->uv_domain.max.y = 2*pi; - surface->parameterization_on_v_coeff_a = -1; - surface->parameterization_on_v_coeff_b = 2*pi; - - surface->has_transformation = true; - surface->geometry_is_2D = false; - surface->behaviour = PRC_TRANSFORMATION_Translate|PRC_TRANSFORMATION_Rotate; - surface->origin.Set(0,0,0); - surface->x_axis.Set(1,0,0); - surface->y_axis.Set(0,1,0); - - PRCBrepModel *brepmodel = new PRCBrepModel("disk"); - brepmodel->context_id = context_index; - brepmodel->body_id = body_index; - brepmodel->is_closed = true; // we do not need to see the tube from inside - brepmodel->index_of_line_style = 0; -// file.addBrepModel(brepmodel); - - PRCSingleWireBody *firstCurveBody = new PRCSingleWireBody; - uint32_t first_curve_body_index = diskContext->addSingleWireBody(firstCurveBody); - PRCWireEdge *firstCurveEdge = new PRCWireEdge; - firstCurveBody->setWireEdge(firstCurveEdge); - firstCurveEdge->curve_3d = surface->first_curve; - PRCWire *firstCurveWire = new PRCWire("firstCurveWire"); - firstCurveWire->index_of_line_style = 0; - firstCurveWire->context_id = context_index; - firstCurveWire->body_id = first_curve_body_index; -// file.addWire(firstCurveWire); - } - if(1) { PRCmaterial materialGreen( RGBAColour(0.0,0.18,0.0), @@ -523,242 +869,82 @@ if(1) { RGBAColour(0.0,0.32,0.0), RGBAColour(0.0,0.072,0.0), 1.0,0.1); + PRCoptions grpopt; + grpopt.closed = true; + + file.begingroup("Complex elements, one-sided"); const double disk_origin[3] = {11,0,2}; const double disk_x_axis[3] = {1,0,0}; const double disk_y_axis[3] = {0,-1,0}; const double disk_scale = 2; - file.begingroup("diskPRCCLOSED"); + file.begingroup("disk",&grpopt); file.addDisk(1,materialGreen,disk_origin,disk_x_axis,disk_y_axis,disk_scale); file.endgroup(); const double hs_origin[3] = {11,0,2}; const double hs_x_axis[3] = {1,0,0}; const double hs_y_axis[3] = {0,1,0}; const double hs_scale = 2; - file.begingroup("hemispherePRCCLOSED"); + file.begingroup("hemisphere",&grpopt); file.addHemisphere(1,materialGreen,hs_origin,hs_x_axis,hs_y_axis,hs_scale); file.endgroup(); const double cyl_origin[3] = {11,0,1}; const double cyl_x_axis[3] = {1,0,0}; const double cyl_y_axis[3] = {0,1,0}; const double cyl_scale = 1; - file.begingroup("cylinderPRCCLOSED"); + file.begingroup("cylinder",&grpopt); file.addCylinder(1,1,materialGreen,cyl_origin,cyl_x_axis,cyl_y_axis,cyl_scale); file.endgroup(); - const double sp_origin[3] = {11,0,1}; + const double cone_origin[3] = {11,0,1}; + const double cone_x_axis[3] = {1,0,0}; + const double cone_y_axis[3] = {0,-1,0}; + const double cone_scale = 1; + file.begingroup("cone",&grpopt); + file.addCone(1,1,materialGreen,cone_origin,cone_x_axis,cone_y_axis,cone_scale); + file.endgroup(); + const double sp_origin[3] = {11,0,-1}; const double sp_x_axis[3] = {1,0,0}; const double sp_y_axis[3] = {0,1,0}; const double sp_scale = 1; - file.begingroup("spherePRCCLOSED"); + file.begingroup("sphere",&grpopt); file.addSphere(0.5,materialGreen,sp_origin,sp_x_axis,sp_y_axis,sp_scale); file.endgroup(); const double tor_origin[3] = {11,0,0}; const double tor_x_axis[3] = {1,0,0}; const double tor_y_axis[3] = {0,1,0}; const double tor_scale = 1; - file.begingroup("torusPRCCLOSED"); + file.begingroup("torus",&grpopt); file.addTorus(0.5,0.1,0,360,materialGreen,tor_origin,tor_x_axis,tor_y_axis,tor_scale); file.endgroup(); + + const size_t NUMBER_OF_POINTS = 4; + double cpoints[NUMBER_OF_POINTS][3]; + cpoints[0][0] = 1; cpoints[0][1] = 0; cpoints[0][2] = 0; + cpoints[1][0] = 1; cpoints[1][1] = 0.552284749830793; cpoints[1][2] = 0; + cpoints[2][0] = 0.552284749830793; cpoints[2][1] = 1; cpoints[2][2] = 0; + cpoints[3][0] = 0; cpoints[3][1] = 1; cpoints[3][2] = 0; + double opoints[NUMBER_OF_POINTS][3]; + opoints[0][0] = 1.1*1; opoints[0][1] = 1.1*0; opoints[0][2] = 0; + opoints[1][0] = 1.1*1; opoints[1][1] = 1.1*0.552284749830793; opoints[1][2] = 0; + opoints[2][0] = 1.1*0.552284749830793; opoints[2][1] = 1.1*1; opoints[2][2] = 0; + opoints[3][0] = 1.1*0; opoints[3][1] = 1.1*1; opoints[3][2] = 0; + const double tube_origin[3] = {11,0,0}; + const double tube_x_axis[3] = {1,0,0}; + const double tube_y_axis[3] = {0,1,0}; + const double tube_scale = 1; + file.begingroup("tube",&grpopt); + file.addTube(NUMBER_OF_POINTS,cpoints,opoints,false,materialGreen,tube_origin,tube_x_axis,tube_y_axis,tube_scale); + file.endgroup(); + + file.endgroup(); } - if(0) { // Blend01 tube around a Composite curve - no good at corners - const size_t NUMBER_OF_POINTS = 4; - double points[NUMBER_OF_POINTS][3]; - points[0][0] = 1; points[0][1] = 0; points[0][2] = 0; - points[1][0] = 1; points[1][1] = 0.552284749830793; points[1][2] = 0; - points[2][0] = 0.552284749830793; points[2][1] = 1; points[2][2] = 0; - points[3][0] = 0; points[3][1] = 1; points[3][2] = 0; - double qoints[NUMBER_OF_POINTS][3]; - qoints[0][0] = 0; qoints[0][1] = 1; qoints[0][2] = 0; - qoints[1][0] = 0; qoints[1][1] = 1; qoints[1][2] = 0.552284749830793; - qoints[2][0] = 0; qoints[2][1] = 0.552284749830793; qoints[2][2] = 1; - qoints[3][0] = 0; qoints[3][1] = 0; qoints[3][2] = 1; -// for(size_t i = 0; i < NUMBER_OF_POINTS; ++i) -// { -// points[i][0] = 3.5*cos(3.0*i/NUMBER_OF_POINTS*2.0*pi); -// points[i][1] = 3.5*sin(3.0*i/NUMBER_OF_POINTS*2.0*pi); -// points[i][2] = 5.0*i/NUMBER_OF_POINTS-1.0; -// } - - double knots[3+NUMBER_OF_POINTS+1]; - knots[0] = 1; - for(size_t i = 1; i < 3+NUMBER_OF_POINTS; ++i) - { - knots[i] = (i+2)/3; // integer division is intentional - } - knots[3+NUMBER_OF_POINTS] = (3+NUMBER_OF_POINTS+1)/3; - - PRCTopoContext *tubeContext = new PRCTopoContext; - uint32_t context_index = file.addTopoContext(tubeContext); - - PRCBrepData *body = new PRCBrepData; - uint32_t body_index = tubeContext->addBrepData(body); - PRCConnex *connex = new PRCConnex; - body->addConnex(connex); - PRCShell *shell = new PRCShell; - connex->addShell(shell); - PRCFace *face = new PRCFace; - shell->addFace(face); - PRCBlend01 *surface = new PRCBlend01; - face->base_surface=surface; - - PRCNURBSCurve *center_curve = new PRCNURBSCurve; - center_curve->is_rational = false; - center_curve->degree = 3; - for(size_t i = 0; i < NUMBER_OF_POINTS; ++i) - center_curve->control_point.push_back(PRCControlPoint(points[i][0]+0.0,points[i][1],points[i][2])); - for(size_t i = 0; i < 3+NUMBER_OF_POINTS+1; ++i) - center_curve->knot.push_back(knots[i]); - surface->center_curve=center_curve; - - PRCNURBSCurve *origin_curve = new PRCNURBSCurve; - origin_curve->is_rational = false; - origin_curve->degree = 3; - for(size_t i = 0; i < NUMBER_OF_POINTS; ++i) - origin_curve->control_point.push_back(PRCControlPoint(points[i][0]*1.01+0.0,points[i][1]*1.01,points[i][2])); - for(size_t i = 0; i < 3+NUMBER_OF_POINTS+1; ++i) - origin_curve->knot.push_back(knots[i]); - surface->origin_curve=origin_curve; - - surface->uv_domain.min.x = 0; - surface->uv_domain.max.x = 2*pi; - surface->uv_domain.min.y = 1; // first knot - surface->uv_domain.max.y = 2; // last knot - PRCBrepModel *brepmodel = new PRCBrepModel("Tube"); - brepmodel->context_id = context_index; - brepmodel->body_id = body_index; - brepmodel->is_closed = true; // we do not need to see the tube from inside - brepmodel->index_of_line_style = 0; -// file.addBrepModel(brepmodel); - - PRCSingleWireBody *originCurveBody = new PRCSingleWireBody; - uint32_t origin_curve_body_index = tubeContext->addSingleWireBody(originCurveBody); - PRCWireEdge *originCurveEdge = new PRCWireEdge; - originCurveBody->setWireEdge(originCurveEdge); - originCurveEdge->curve_3d = surface->origin_curve; - PRCWire *originCurveWire = new PRCWire("originCurveWire"); - originCurveWire->index_of_line_style = 0; - originCurveWire->context_id = context_index; - originCurveWire->body_id = origin_curve_body_index; -// file.addWire(originCurveWire); - - PRCSingleWireBody *centerCurveBody = new PRCSingleWireBody; - uint32_t center_curve_body_index = tubeContext->addSingleWireBody(centerCurveBody); - PRCWireEdge *centerCurveEdge = new PRCWireEdge; - centerCurveBody->setWireEdge(centerCurveEdge); - centerCurveEdge->curve_3d = surface->center_curve; - PRCWire *centerCurveWire = new PRCWire("centerCurveWire"); - centerCurveWire->index_of_line_style = 0; - centerCurveWire->context_id = context_index; - centerCurveWire->body_id = center_curve_body_index; -// file.addWire(centerCurveWire); - - PRCNURBSCurve *Center_curve = new PRCNURBSCurve; - Center_curve->is_rational = false; - Center_curve->degree = 3; - for(size_t i = 0; i < NUMBER_OF_POINTS; ++i) - Center_curve->control_point.push_back(PRCControlPoint(qoints[i][0],qoints[i][1],qoints[i][2])); - for(size_t i = 0; i < 3+NUMBER_OF_POINTS+1; ++i) - Center_curve->knot.push_back(knots[i]); - - PRCNURBSCurve *Origin_curve = new PRCNURBSCurve; - Origin_curve->is_rational = false; - Origin_curve->degree = 3; - for(size_t i = 0; i < NUMBER_OF_POINTS; ++i) - Origin_curve->control_point.push_back(PRCControlPoint(qoints[i][0],qoints[i][1]*1.01,qoints[i][2]*1.01)); - for(size_t i = 0; i < 3+NUMBER_OF_POINTS+1; ++i) - Origin_curve->knot.push_back(knots[i]); - - PRCSingleWireBody *OriginCurveBody = new PRCSingleWireBody; - uint32_t Origin_curve_body_index = tubeContext->addSingleWireBody(OriginCurveBody); - PRCWireEdge *OriginCurveEdge = new PRCWireEdge; - OriginCurveBody->setWireEdge(OriginCurveEdge); -// OriginCurveEdge->origin_curve=Origin_curve; - PRCWire *OriginCurveWire = new PRCWire("OriginCurveWire"); - OriginCurveWire->index_of_line_style = 0; - OriginCurveWire->context_id = context_index; - OriginCurveWire->body_id = Origin_curve_body_index; -// file.addWire(OriginCurveWire); - - PRCSingleWireBody *CenterCurveBody = new PRCSingleWireBody; - uint32_t Center_curve_body_index = tubeContext->addSingleWireBody(CenterCurveBody); - PRCWireEdge *CenterCurveEdge = new PRCWireEdge; - CenterCurveBody->setWireEdge(CenterCurveEdge); -// CenterCurveEdge->setCurve(Center_curve); - PRCWire *CenterCurveWire = new PRCWire("CenterCurveWire"); - CenterCurveWire->index_of_line_style = 0; - CenterCurveWire->context_id = context_index; - CenterCurveWire->body_id = Center_curve_body_index; -// file.addWire(CenterCurveWire); - - PRCComposite *compositeCenter_curve = new PRCComposite; - compositeCenter_curve->base_curve.push_back(centerCurveEdge->curve_3d); - compositeCenter_curve->base_sense.push_back(true); - compositeCenter_curve->base_curve.push_back(CenterCurveEdge->curve_3d); - compositeCenter_curve->base_sense.push_back(true); - compositeCenter_curve->is_closed = false; - compositeCenter_curve->interval.min = 0; - compositeCenter_curve->interval.max = 2; - - PRCSingleWireBody *compositeCenterCurveBody = new PRCSingleWireBody; - uint32_t compositeCenter_curve_body_index = tubeContext->addSingleWireBody(compositeCenterCurveBody); - PRCWireEdge *compositeCenterCurveEdge = new PRCWireEdge; - compositeCenterCurveBody->setWireEdge(compositeCenterCurveEdge); -// compositeCenterCurveEdge->setCurve(compositeCenter_curve); - PRCWire *compositeCenterCurveWire = new PRCWire("compositeCenterCurveWire"); - compositeCenterCurveWire->index_of_line_style = 0; - compositeCenterCurveWire->context_id = context_index; - compositeCenterCurveWire->body_id = compositeCenter_curve_body_index; -// file.addWire(compositeCenterCurveWire); - - PRCComposite *compositeOrigin_curve = new PRCComposite; - compositeOrigin_curve->base_curve.push_back(originCurveEdge->curve_3d); - compositeOrigin_curve->base_sense.push_back(true); - compositeOrigin_curve->base_curve.push_back(OriginCurveEdge->curve_3d); - compositeOrigin_curve->base_sense.push_back(true); - compositeOrigin_curve->is_closed = false; - compositeOrigin_curve->interval.min = 0; - compositeOrigin_curve->interval.max = 2; - - PRCSingleWireBody *compositeOriginCurveBody = new PRCSingleWireBody; - uint32_t compositeOrigin_curve_body_index = tubeContext->addSingleWireBody(compositeOriginCurveBody); - PRCWireEdge *compositeOriginCurveEdge = new PRCWireEdge; - compositeOriginCurveBody->setWireEdge(compositeOriginCurveEdge); -// compositeOriginCurveEdge->setCurve(compositeOrigin_curve); - PRCWire *compositeOriginCurveWire = new PRCWire("compositeOriginCurveWire"); - compositeOriginCurveWire->index_of_line_style = 0; - compositeOriginCurveWire->context_id = context_index; - compositeOriginCurveWire->body_id = compositeOrigin_curve_body_index; -// file.addWire(compositeOriginCurveWire); - - PRCBrepData *cbody = new PRCBrepData; - uint32_t cbody_index = tubeContext->addBrepData(cbody); - PRCConnex *cconnex = new PRCConnex; - cbody->addConnex(cconnex); - PRCShell *cshell = new PRCShell; - cconnex->addShell(cshell); - PRCFace *cface = new PRCFace; - cshell->addFace(cface); - PRCBlend01 *csurface = new PRCBlend01; - cface->base_surface=csurface; - - csurface->uv_domain.min.x = 0; - csurface->uv_domain.max.x = 2*pi; - csurface->uv_domain.min.y = 0; // first knot - csurface->uv_domain.max.y = 2; // last knot - csurface->center_curve = compositeCenterCurveEdge->curve_3d; - csurface->origin_curve = compositeOriginCurveEdge->curve_3d; - PRCBrepModel *cbrepmodel = new PRCBrepModel("cTube"); - cbrepmodel->context_id = context_index; - cbrepmodel->body_id = cbody_index; - cbrepmodel->is_closed = true; // we do not need to see the tube from inside - cbrepmodel->index_of_line_style = 0; -// file.addBrepModel(cbrepmodel); - - - } - - file.finish(); + file.finish(); + + delete[] picture1; + delete[] picture2; + delete[] picture3; + delete[] picture4; return 0; } diff --git a/Build/source/utils/asymptote/prc/writePRC.cc b/Build/source/utils/asymptote/prc/writePRC.cc index 7e1e1358bd9..ecc6179b36c 100644 --- a/Build/source/utils/asymptote/prc/writePRC.cc +++ b/Build/source/utils/asymptote/prc/writePRC.cc @@ -29,6 +29,10 @@ #include <fstream> #include <sstream> +#ifndef __GNUC__ +#include <vector> +#endif + using namespace std; #ifndef __GNUC_PREREQ @@ -112,7 +116,23 @@ uint32_t Log2(uint32_t x) #define SerializeContentSingleAttribute( value ) (value).serializeSingleAttribute(pbs); #define SerializeAttribute( value ) (value).serializeAttribute(pbs); #define SerializeAttributeData serializeAttributes(pbs); +#define WriteUncompressedUnsignedInteger( value ) writeUncompressedUnsignedInteger(out, (uint32_t)(value)); +#define SerializeFileStructureUncompressedUniqueId( value ) (value).serializeFileStructureUncompressedUniqueId(out); +void writeUncompressedUnsignedInteger(ostream &out, uint32_t data) +{ +#ifdef WORDS_BIGENDIAN + out.write(((char*)&data)+3,1); + out.write(((char*)&data)+2,1); + out.write(((char*)&data)+1,1); + out.write(((char*)&data)+0,1); +#else + out.write(((char*)&data)+0,1); + out.write(((char*)&data)+1,1); + out.write(((char*)&data)+2,1); + out.write(((char*)&data)+3,1); +#endif +} double PRCVector3d::Length() { @@ -139,7 +159,7 @@ void UserData::write(PRCbitStream &pbs) for(uint32_t i = 0; i < quot; ++i) pbs << data[i]; for(uint32_t j = 0; j < rem; ++j) // 0-based, big endian bit counting - pbs << (bool)(data[quot] & (0x80 >> j)); + pbs << (bool)((data[quot] & (0x80 >> j))!=0); } } @@ -412,7 +432,7 @@ uint32_t current_layer_index = m1; uint32_t current_index_of_line_style = m1; uint16_t current_behaviour_bit_field = 1; -void writeGraphics(PRCbitStream &pbs,uint32_t l,uint32_t i,uint32_t b,bool force) +void writeGraphics(PRCbitStream &pbs,uint32_t l,uint32_t i,uint16_t b,bool force) { if(force || current_layer_index != l || current_index_of_line_style != i || current_behaviour_bit_field != b) { @@ -974,9 +994,7 @@ uint32_t makePRCID() void writeUnit(PRCbitStream &out,bool fromCAD,double unit) { - static const double inches=72; - static const double cm=inches/2.54; - out << fromCAD << 10.0/cm; // Use bp. + out << fromCAD << unit; } void writeEmptyMarkups(PRCbitStream &out) @@ -1273,13 +1291,23 @@ void PRCCompressedFace::serializeCompressedNurbs(PRCbitStream &pbs, double brep const uint32_t number_of_control_point_in_u = degree_in_u + 1; const uint32_t number_of_control_point_in_v = degree_in_v + 1; + +#ifdef __GNUC__ PRCVector3d P[number_of_control_point_in_u][number_of_control_point_in_v]; +#else + vector<vector<PRCVector3d> > P(number_of_control_point_in_u, vector<PRCVector3d>(number_of_control_point_in_v)); +#endif for(uint32_t i=0;i<number_of_control_point_in_u;i++) for(uint32_t j=0;j<number_of_control_point_in_v;j++) P[i][j] = control_point[i*number_of_control_point_in_v+j]; +#ifdef __GNUC__ itriple compressed_control_point[number_of_control_point_in_u][number_of_control_point_in_v]; uint32_t control_point_type[number_of_control_point_in_u][number_of_control_point_in_v]; - +#else + vector<vector<itriple> > compressed_control_point(number_of_control_point_in_u, vector<itriple>(number_of_control_point_in_v)); + vector<vector<uint32_t> > control_point_type(number_of_control_point_in_u, vector<uint32_t>(number_of_control_point_in_v)); +#endif + uint32_t number_of_bits_for_isomin = 1; uint32_t number_of_bits_for_rest = 1; @@ -1491,6 +1519,17 @@ void PRCSphere::serializeSphere(PRCbitStream &pbs) WriteDouble ( radius ) } +void PRCCone::serializeCone(PRCbitStream &pbs) +{ + WriteUnsignedInteger (PRC_TYPE_SURF_Cone) + + SerializeContentSurface + SerializeTransformation + SerializeUVParameterization + WriteDouble ( bottom_radius ) + WriteDouble ( semi_angle ) +} + void PRCCylinder::serializeCylinder(PRCbitStream &pbs) { WriteUnsignedInteger (PRC_TYPE_SURF_Cylinder) @@ -1815,24 +1854,32 @@ uint32_t PRCTopoContext::addCompressedBrepData(PRCCompressedBrepData*& pCompress void PRCSingleWireBody::serializeSingleWireBody(PRCbitStream &pbs) { - WriteUnsignedInteger ( PRC_TYPE_TOPO_SingleWireBody) + WriteUnsignedInteger ( PRC_TYPE_TOPO_SingleWireBody) - SerializeContentBody - SerializePtrTopology ( wire_edge ) + SerializeContentBody + SerializePtrTopology ( wire_edge ) +} + +void PRCUniqueId::serializeCompressedUniqueId(PRCbitStream &pbs) const +{ + WriteUnsignedInteger (id0) + WriteUnsignedInteger (id1) + WriteUnsignedInteger (id2) + WriteUnsignedInteger (id3) } -void PRCUniqueId::serializeCompressedUniqueId(PRCbitStream &pbs) +void PRCUniqueId::serializeFileStructureUncompressedUniqueId(std::ostream& out) const { - WriteUnsignedInteger (unique_id0) - WriteUnsignedInteger (unique_id1) - WriteUnsignedInteger (unique_id2) - WriteUnsignedInteger (unique_id3) + WriteUncompressedUnsignedInteger (id0) + WriteUncompressedUnsignedInteger (id1) + WriteUncompressedUnsignedInteger (id2) + WriteUncompressedUnsignedInteger (id3) } void PRCUnit::serializeUnit(PRCbitStream &pbs) { - WriteBoolean (unit_from_CAD_file) - WriteDouble (unit) + WriteBoolean (unit_from_CAD_file) + WriteDouble (unit) } void PRCProductOccurrence::serializeProductOccurrence(PRCbitStream &pbs) @@ -1872,7 +1919,7 @@ void PRCProductOccurrence::serializeProductOccurrence(PRCbitStream &pbs) const bool has_location = location != NULL; WriteBit (has_location) if (has_location) - location->serializeTransformation3d (pbs); + location->serializeTransformation3d (pbs); WriteUnsignedInteger (0) // number_of_references diff --git a/Build/source/utils/asymptote/prc/writePRC.h b/Build/source/utils/asymptote/prc/writePRC.h index 2ec5ebc427d..390e8042150 100644 --- a/Build/source/utils/asymptote/prc/writePRC.h +++ b/Build/source/utils/asymptote/prc/writePRC.h @@ -24,7 +24,9 @@ #include <vector> #include <deque> #include <list> +#ifdef __GNUC__ #include <ext/slist> +#endif #include <map> #include <iostream> #include "PRCbitStream.h" @@ -33,7 +35,7 @@ #include <math.h> static const uint32_t m1=(uint32_t)-1; -static const double pi=acos(-1); +static const double pi=acos(-1.0); class PRCVector3d { @@ -100,7 +102,7 @@ public : return out; } }; - +/* class UUID { public: @@ -112,7 +114,9 @@ class UUID } private: uint32_t id0,id1,id2,id3; -}; +}; */ + +void writeUncompressedUnsignedInteger(std::ostream &out, uint32_t data); uint32_t makeCADID(); uint32_t makePRCID(); @@ -243,7 +247,7 @@ class ContentPRCBase : public PRCAttributes name(n),type_eligible_for_reference(efr),CAD_identifier(ci), CAD_persistent_identifier(cpi),PRC_unique_identifier(pi) {} void serializeContentPRCBase(PRCbitStream&); - uint32_t getPRCID() { return PRC_unique_identifier; } + uint32_t getPRCID() const { return PRC_unique_identifier; } std::string name; bool type_eligible_for_reference; uint32_t CAD_identifier, CAD_persistent_identifier, PRC_unique_identifier; @@ -271,7 +275,7 @@ extern uint32_t current_layer_index; extern uint32_t current_index_of_line_style; extern uint16_t current_behaviour_bit_field; -void writeGraphics(PRCbitStream&,uint32_t=m1,uint32_t=m1,uint32_t=1,bool=false); +void writeGraphics(PRCbitStream&,uint32_t=m1,uint32_t=m1,uint16_t=1,bool=false); void resetGraphics(); void resetGraphicsAndName(); @@ -581,6 +585,7 @@ public: PRCRepresentationItemContent(n) {} virtual ~PRCRepresentationItem() {} virtual void serializeRepresentationItem(PRCbitStream &pbs) = 0; + virtual uint32_t getType() const = 0; }; typedef std::deque <PRCRepresentationItem*> PRCRepresentationItemList; @@ -591,6 +596,7 @@ public: PRCRepresentationItem(n), has_brep_data(true), context_id(m1), body_id(m1), is_closed(false) {} void serializeBrepModel(PRCbitStream&); void serializeRepresentationItem(PRCbitStream &pbs) { serializeBrepModel(pbs); } + uint32_t getType() const { return PRC_TYPE_RI_BrepModel; } bool has_brep_data; uint32_t context_id; uint32_t body_id; @@ -604,6 +610,7 @@ public: PRCRepresentationItem(n), is_closed(false) {} void serializePolyBrepModel(PRCbitStream&); void serializeRepresentationItem(PRCbitStream &pbs) { serializePolyBrepModel(pbs); } + uint32_t getType() const { return PRC_TYPE_RI_PolyBrepModel; } bool is_closed; }; @@ -614,6 +621,7 @@ public: PRCRepresentationItem(n) {} void serializePointSet(PRCbitStream&); void serializeRepresentationItem(PRCbitStream &pbs) { serializePointSet(pbs); } + uint32_t getType() const { return PRC_TYPE_RI_PointSet; } std::vector<PRCVector3d> point; }; @@ -624,6 +632,7 @@ public: PRCRepresentationItem(n), has_wire_body(true), context_id(m1), body_id(m1) {} void serializeWire(PRCbitStream&); void serializeRepresentationItem(PRCbitStream &pbs) { serializeWire(pbs); } + uint32_t getType() const { return PRC_TYPE_RI_Curve; } bool has_wire_body; uint32_t context_id; uint32_t body_id; @@ -636,6 +645,7 @@ public: PRCRepresentationItem(n) {} void serializePolyWire(PRCbitStream&); void serializeRepresentationItem(PRCbitStream &pbs) { serializePolyWire(pbs); } + uint32_t getType() const { return PRC_TYPE_RI_PolyWire; } }; class PRCSet : public PRCRepresentationItem @@ -653,6 +663,7 @@ public: uint32_t addWire(PRCWire*& pWire); uint32_t addPolyWire(PRCPolyWire*& pPolyWire); uint32_t addRepresentationItem(PRCRepresentationItem*& pRepresentationItem); + uint32_t getType() const { return PRC_TYPE_RI_Set; } PRCRepresentationItemList elements; }; @@ -807,7 +818,9 @@ public: ~PRCCoordinateSystem() { delete axis_set; } void serializeCoordinateSystem(PRCbitStream&); void serializeRepresentationItem(PRCbitStream &pbs) { serializeCoordinateSystem(pbs); } - void setAxisSet(PRCTransformation3d*& transform) { axis_set = transform; transform = NULL; } + void setAxisSet(PRCGeneralTransformation3d*& transform) { axis_set = transform; transform = NULL; } + void setAxisSet(PRCCartesianTransformation3d*& transform) { axis_set = transform; transform = NULL; } + uint32_t getType() const { return PRC_TYPE_RI_CoordinateSystem; } PRCTransformation3d *axis_set; bool operator==(const PRCCoordinateSystem &t) const { @@ -1093,6 +1106,19 @@ public: double radius; }; +class PRCCone : public PRCSurface, public PRCTransformation, public PRCUVParameterization +{ +public: + PRCCone() : + PRCSurface() {} + PRCCone(std::string n) : + PRCSurface(n) {} + void serializeCone(PRCbitStream &pbs); + void serializeSurface(PRCbitStream &pbs) { serializeCone(pbs); } + double bottom_radius; + double semi_angle; +}; + class PRCCylinder : public PRCSurface, public PRCTransformation, public PRCUVParameterization { public: @@ -1335,18 +1361,20 @@ typedef std::deque <PRCTopoContext*> PRCTopoContextList; class PRCUniqueId { public: - PRCUniqueId() : unique_id0(0), unique_id1(0), unique_id2(0), unique_id3(0) {} - void serializeCompressedUniqueId(PRCbitStream&); - uint32_t unique_id0; - uint32_t unique_id1; - uint32_t unique_id2; - uint32_t unique_id3; + PRCUniqueId() : id0(0), id1(0), id2(0), id3(0) {} + void serializeCompressedUniqueId(PRCbitStream&) const; + void serializeFileStructureUncompressedUniqueId(std::ostream& out) const; + uint32_t id0; + uint32_t id1; + uint32_t id2; + uint32_t id3; }; class PRCUnit { public: PRCUnit() : unit_from_CAD_file(false), unit(1) {} + PRCUnit(double u, bool ufcf=true) : unit_from_CAD_file(ufcf), unit(u) {} void serializeUnit(PRCbitStream&); bool unit_from_CAD_file; double unit; |