Esempio n. 1
0
void GLC_WorldTo3dxml::write3DRep(const GLC_3DRep* pRep, const QString& fileName)
{
	setStreamWriterToFile(fileName);

	m_pOutStream->writeStartDocument();
	m_pOutStream->writeStartElement("XMLRepresentation");
	m_pOutStream->writeAttribute("version", "1.2");
	m_pOutStream->writeAttribute("xmlns", "http://www.3ds.com/xsd/3DXML");
	m_pOutStream->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
	m_pOutStream->writeAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
	m_pOutStream->writeAttribute("xsi:schemaLocation", "http://www.3ds.com/xsd/3DXML ./3DXMLMesh.xsd");

	m_pOutStream->writeStartElement("Root"); // Root
	m_pOutStream->writeAttribute("xsi:type", "BagRepType");
	m_pOutStream->writeAttribute("id", QString::number(++m_CurrentId));
	const int bodyCount= pRep->numberOfBody();
	for (int i= 0; i < bodyCount; ++i)
	{
		GLC_Mesh* pMesh= dynamic_cast<GLC_Mesh*>(pRep->geomAt(i));
		if (NULL != pMesh)
		{
			writeGeometry(pMesh);
		}
	}
	m_pOutStream->writeEndElement(); // Root

	m_pOutStream->writeEndElement(); // XMLRepresentation

	m_pOutStream->writeEndDocument();
}
Esempio n. 2
0
bool CityGMLWriter::write_CityGML(int buildLoD) {
	/*Write the building to the CityGML file*/
	
	if (gml_ofstream.is_open())	{						// Check if open
		writeHeader();
		writeGeometryHeader(0,0);
								writeGeometry(exPolVector	,0,buildLoD); 
		if (has_BuildInstalls)	writeGeometry(biPolVector	,1,3);
		if (has_BuildParts)		writeGeometry(bpPolVector	,2,3);
		if (has_LoD4Rooms)		writeGeometry(lod4PolVector	,3,4);

		
		writeGeometryFooter(0);
		//writeAddress(); 
		//writeAppearance();				// move one up to make it within the building bla

		writeFooter();
		gml_ofstream.close();							// Close file
		return true;
	} else std::cerr << "ERROR: Can't open file: " << filename_0ext << ".gml" <<std::endl;
	return false;
}
Esempio n. 3
0
	bool ModelConverter::startConversionJob( ConversionResult& result, const ConversionParameters& parameters ) const
	{
		for( uint fileIndex = 0u; fileIndex < parameters.inputFiles.getCount(); ++fileIndex )
		{
			const ConversionParameters::InputFile& file = parameters.inputFiles[ fileIndex ];

			const string material	= parameters.arguments.getOptionalString( "material", "" );
			const float scale		= parameters.arguments.getOptionalFloat( "scale", 1.0f );
			const bool calcTangents	= parameters.arguments.getOptionalBool( "calculate_tangents", true );

			ToolModel model;
			model.create( file.fileName, scale );
			model.parseGeometies( calcTangents );

			ResourceWriter writer;
			openResourceWriter( writer, result, parameters.outputName, "model" );

			for (const ResourceDefinition& definition : getResourceDefinitions())
			{
				writer.openResource( parameters.outputName + ".model", TIKI_FOURCC( 'M', 'O', 'D', 'L' ), definition, getConverterRevision( s_typeCrc ) );

				// write hierarchy
				const ReferenceKey* pHierarchyKey = nullptr;
				ReferenceKey hierarchyKey;
				if ( model.getHierarchy().isCreated() )
				{
					hierarchyKey = writeHierarchy( writer, model.getHierarchy() );
					pHierarchyKey = &hierarchyKey;
				}

				// write vertex data
				List< ReferenceKey > geometryKeys;

				bool wrongSkinned = false;
				for (uint geometryIndex = 0u; geometryIndex < model.getGeometyCount(); ++geometryIndex )
				{
					const ReferenceKey key = writeGeometry( writer, model.getGeometryByIndex( geometryIndex ) );
					geometryKeys.add( key );

					for (uint k = 0u; k < model.getGeometyCount(); ++k)
					{
						if ( model.getGeometryByIndex( geometryIndex ).getDesc().isSkinned != model.getGeometryByIndex( k ).getDesc().isSkinned )
						{
							wrongSkinned = true;
						}
					}
				}

				if ( wrongSkinned )
				{
					TIKI_TRACE_ERROR( "[modelconverter] Not every Mesh is skinned.\n" );
				}

				writer.openDataSection( 0u, AllocatorType_InitializaionMemory );
				writeResourceReference( writer, material );
				writer.writeReference( pHierarchyKey );
				writer.writeUInt32( uint32( model.getGeometyCount() ) );
				for( uint geometryIndex = 0u; geometryIndex < geometryKeys.getCount(); ++geometryIndex )
				{
					writer.writeReference( &geometryKeys[ geometryIndex ] );
				}			
				writer.closeDataSection();

				writer.closeResource();
			}
			
			closeResourceWriter( writer );

			model.dispose();
		}

		return true;
	}
Esempio n. 4
0
int main(int argc, char *argv[])
{
  bool_t analyze_output, equilibria_only;
  int    niter, nact;

  Atom *atom;
  Molecule *molecule;

  /* --- Read input data and initialize --             -------------- */

  setOptions(argc, argv);
  getCPU(0, TIME_START, NULL);
  SetFPEtraps();

  readInput();
  spectrum.updateJ = TRUE;
 
  getCPU(1, TIME_START, NULL);
  readAtmos(&atmos, &geometry);
  if (atmos.Stokes) Bproject();
  fillMesh(&geometry);

  readAtomicModels();
  readMolecularModels();
  SortLambda();
  
  getBoundary(&atmos, &geometry);

  Background(analyze_output=TRUE, equilibria_only=FALSE);

  getProfiles();
  initSolution();
  initScatter();

  getCPU(1, TIME_POLL, "Total initialize");
 
  /* --- Solve radiative transfer for active ingredients -- --------- */

  Iterate(input.NmaxIter, input.iterLimit);

  adjustStokesMode(atom);
  niter = 0;
  while (niter < input.NmaxScatter) {  
    if (solveSpectrum(FALSE, FALSE) <= input.iterLimit) break;
    niter++;
  }
  /* --- Write output files --                     ------------------ */
 
  getCPU(1, TIME_START, NULL);

  writeInput();
  writeAtmos(&atmos);
  writeGeometry(&geometry);
  writeSpectrum(&spectrum);
  writeFlux(FLUX_DOT_OUT);

  for (nact = 0;  nact < atmos.Nactiveatom;  nact++) {
    atom = atmos.activeatoms[nact];

    writeAtom(atom);
    writePopulations(atom);
    writeRadRate(atom);
    writeCollisionRate(atom);
    writeDamping(atom);
  } 
  for (nact = 0;  nact < atmos.Nactivemol;  nact++) {
    molecule = atmos.activemols[nact];
    writeMolPops(molecule);
  }

  writeOpacity();

  getCPU(1, TIME_POLL, "Write output");
  printTotalCPU();
}
bool ossimKakaduNitfWriter::writeStream()
{
   static const char MODULE[] = "ossimKakaduNitfWriter::writeStream";

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " entered..." << endl;
   }

   if ( !theInputConnection || !m_outputStream || !theInputConnection->isMaster() )
   {
      return false;
   }

   const ossim_uint32    TILES  = theInputConnection->getNumberOfTiles();
   const ossim_uint32    BANDS  = theInputConnection->getNumberOfOutputBands();
   const ossimScalarType SCALAR = theInputConnection->getOutputScalarType();
   
   if (m_compressor->getAlphaChannelFlag())
   {
      //--- 
      // Someone can set this through the generic setProperty interface.
      // Unset, currently only supported in jp2 writer.
      // Could be used here but I think we would have to update the
      // nitf tags.
      //---
      m_compressor->setAlphaChannelFlag(false);
   }

   // Create the compressor.  Can through an exception.
   try
   {
      m_compressor->create(m_outputStream,
                           SCALAR,
                           BANDS,
                           theInputConnection->getAreaOfInterest(),
                           DEFAULT_TILE_SIZE,
                           TILES,
                           false);
   }
   catch (const ossimException& e)
   {
      ossimNotify(ossimNotifyLevel_WARN) << e.what() << std::endl;
      return false;
   }

   std::streampos endOfFileHdrPos;
   std::streampos endOfImgHdrPos;
   std::streampos endOfFilePos;
   
   // Container record withing NITF file header.
   ossimNitfImageInfoRecordV2_1 imageInfoRecord;
   
   // NITF file header.
   ossimRefPtr<ossimNitfFileHeaderV2_1> fHdr = new ossimNitfFileHeaderV2_1();
   
   // Note the sub header length and image length will be set later.      
   fHdr->addImageInfoRecord(imageInfoRecord);
   
   fHdr->setDate(ossimDate());
   fHdr->setTitle(ossimString("")); // ???
   
   // Write to stream capturing the stream position for later.
   fHdr->writeStream(*m_outputStream);
   endOfFileHdrPos = m_outputStream->tellp();
   
   // NITF image header.
   ossimRefPtr<ossimNitfImageHeaderV2_1> iHdr = new ossimNitfImageHeaderV2_1();
   
   // Set the compression type:
   iHdr->setCompression(ossimString("C8"));
   
   // Set the Image Magnification (IMAG) field.
   iHdr->setImageMagnification(ossimString("1.0"));
   
   // Set the pixel type (PVTYPE) field.
   iHdr->setPixelType(ossimNitfCommon::getNitfPixelType(SCALAR));
   
   // Set the actual bits per pixel (ABPP) field.
   ossim_uint32 abpp = ossim::getActualBitsPerPixel(SCALAR);
   iHdr->setActualBitsPerPixel( abpp );
   
   // Set the bits per pixel (NBPP) field.
   iHdr->setBitsPerPixel(ossim::getBitsPerPixel(SCALAR));
   
   iHdr->setNumberOfBands(BANDS);
   iHdr->setImageMode('B'); // IMODE field to blocked.
   
   if( (BANDS == 3) && (SCALAR == OSSIM_UCHAR) )
   {
      iHdr->setRepresentation("RGB");
      iHdr->setCategory("VIS");
   }
   else if(BANDS == 1)
   {
      iHdr->setRepresentation("MONO");
      iHdr->setCategory("MS");
   }
   else
   {
      iHdr->setRepresentation("MULTI");
      iHdr->setCategory("MS");
   }
   
   ossimNitfImageBandV2_1 bandInfo;
   for(ossim_uint32 band = 0; band < BANDS; ++band)
   {
      std::ostringstream out;
      
      out << std::setfill('0')
          << std::setw(2)
          << band;
      
      bandInfo.setBandRepresentation(out.str().c_str());
      iHdr->setBandInfo(band, bandInfo);
   }
   
   ossim_uint32 outputTilesWide = theInputConnection->getNumberOfTilesHorizontal();
   ossim_uint32 outputTilesHigh = theInputConnection->getNumberOfTilesVertical();
   
   iHdr->setBlocksPerRow(outputTilesWide);
   iHdr->setBlocksPerCol(outputTilesHigh);
   iHdr->setNumberOfPixelsPerBlockRow(DEFAULT_TILE_SIZE.y);
   iHdr->setNumberOfPixelsPerBlockCol(DEFAULT_TILE_SIZE.x);
   iHdr->setNumberOfRows(theInputConnection->getAreaOfInterest().height());
   iHdr->setNumberOfCols(theInputConnection->getAreaOfInterest().width());
   
   // Write the geometry info to the image header.
   writeGeometry(iHdr.get(), theInputConnection.get());

   // Add the J2KLRA TRE:
   ossimRefPtr<ossimNitfJ2klraTag> j2klraTag = new ossimNitfJ2klraTag();
   m_compressor->initialize( j2klraTag.get(), abpp );
   j2klraTag->setBandsO( BANDS );
   ossimRefPtr<ossimNitfRegisteredTag> tag = j2klraTag.get();
   ossimNitfTagInformation tagInfo( tag );
   iHdr->addTag( tagInfo );
   
   // Write the image header to stream capturing the stream position.
   iHdr->writeStream(*m_outputStream);
   endOfImgHdrPos = m_outputStream->tellp();
   
   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " DEBUG:"
         << "\noutputTilesWide:  " << outputTilesWide
         << "\noutputTilesHigh:  " << outputTilesHigh
         << "\nnumberOfTiles:    " << TILES
         << "\nimageRect: " << theInputConnection->getAreaOfInterest()
         << std::endl;
   }
   
   // Tile loop in the line direction.
   ossim_uint32 tileNumber = 0;
   bool result = true;
   for(ossim_uint32 y = 0; y < outputTilesHigh; ++y)
   {
      // Tile loop in the sample (width) direction.
      for(ossim_uint32 x = 0; x < outputTilesWide; ++x)
      {
         // Grab the resampled tile.
         ossimRefPtr<ossimImageData> t = theInputConnection->getNextTile();
         if (t.valid() && ( t->getDataObjectStatus() != OSSIM_NULL ) )
         {
            if ( ! m_compressor->writeTile( *(t.get()) ) )
            {
               ossimNotify(ossimNotifyLevel_WARN)
                  << MODULE << " ERROR:"
                  << "Error returned writing tile:  "
                  << tileNumber
                  << std::endl;
               result = false;
            }
         }
         else
         {
            ossimNotify(ossimNotifyLevel_WARN)
               << MODULE << " ERROR:"
               << "Error returned writing tile:  " << tileNumber
               << std::endl;
            result = false;
         }
         if ( !result )
         {
            // This will bust out of both loops.
            x = outputTilesWide;
            y = outputTilesHigh;
         }
         
         // Increment tile number for percent complete.
         ++tileNumber;
         
      } // End of tile loop in the sample (width) direction.
      
      if (needsAborting())
      {
         setPercentComplete(100.0);
         break;
      }
      else
      {
         ossim_float64 tile = tileNumber;
         ossim_float64 numTiles = TILES;
         setPercentComplete(tile / numTiles * 100.0);
      }
      
   } // End of tile loop in the line (height) direction.
         
   m_compressor->finish();
   
   // Get the file length.
   endOfFilePos = m_outputStream->tellp();
   
   //---
   // Seek back to set some things that were not know until now and
   // rewrite the nitf file and image header.
   //---
   m_outputStream->seekp(0, std::ios_base::beg);
   
   // Set the file length.
   std::streamoff length = endOfFilePos;
   fHdr->setFileLength(static_cast<ossim_uint64>(length));
   
   // Set the file header length.
   length = endOfFileHdrPos;
   fHdr->setHeaderLength(static_cast<ossim_uint64>(length));            
   // Set the image sub header length.
   length = endOfImgHdrPos - endOfFileHdrPos;
   
   imageInfoRecord.setSubheaderLength(static_cast<ossim_uint64>(length));
   
   // Set the image length.
   length = endOfFilePos - endOfImgHdrPos;
   imageInfoRecord.setImageLength(static_cast<ossim_uint64>(length));
   
   fHdr->replaceImageInfoRecord(0, imageInfoRecord);
   
   setComplexityLevel(length, fHdr.get());
   
   // Rewrite the header.
   fHdr->writeStream(*m_outputStream);
   
   // Set the compression rate now that the image size is known.
   ossimString comrat = ossimNitfCommon::getCompressionRate(
      theInputConnection->getAreaOfInterest(),
      BANDS,
      SCALAR,
      static_cast<ossim_uint64>(length));
   iHdr->setCompressionRateCode(comrat);
   
   // Rewrite the image header.
   iHdr->writeStream(*m_outputStream);

   close();

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " exit status = " << (result?"true":"false\n")
         << std::endl;
   }
   
   return result;
}