void PulkaReport::makeReport() { QString category = "", vcat; sheet = openDocument(); currentPage = 1; bool start = true; uint draw_number; excel->querySubObject("ActiveWindow")->setProperty("Zoom", 75); const double widths[] = { 21.29, 13.29, 7, 7, 7, 7, 7, 7, 7, 7, 7, 21.29, 13.29, }; for(uint i = 0; i < sizeof(widths)/sizeof(*widths); ++i) { sheet->querySubObject("Columns(const QString&)", QString("%1:%1").arg(QString('A' + i))) ->setProperty("ColumnWidth", widths[i]); } while(query->next()) { vcat = query->value(2).toString(); draw_number = query->value(6).toUInt(); if(start || category != vcat || draw_number > 16) { if(!start) { writeFooter(); } else { start = false; } if(draw_number > 16) draw_number -= 16; category = vcat; writeHeader(category, query->value(0).toString(), query->value(1).toDate()); } writeRec(draw_number); } writeFooter(); sheet->querySubObject("PageSetup")->setProperty("Zoom", 90); sheet->querySubObject("PageSetup")->setProperty("Orientation", xlLandscape); sheet->querySubObject("PageSetup")->setProperty("PrintQuality", 600); }
void ResultsReport::makeReport() { QString category = "", vcat; sheet = openDocument(); currentPage = 1; bool start = true; excel->querySubObject("ActiveWindow")->setProperty("Zoom", 75); const double widths[] = { 3.29, 30, 5.71, 8.43, 18.29, 13.43, 9.57, 13.29, 20.43, 6.43, 7, }; for(uint i = 0; i < sizeof(widths)/sizeof(*widths); ++i) { sheet->querySubObject("Columns(const QString&)", QString("%1:%1").arg(QString('A' + i))) ->setProperty("ColumnWidth", widths[i]); } while(query->next()) { vcat = query->value(0).toString(); if(start || category != vcat) { if(!start) { writeFooter(); } else { start = false; } category = vcat; writeHeader(category, query->value(1).toString(), query->value(2).toDate()); } writeRec(); } writeFooter(); sheet->querySubObject("PageSetup")->setProperty("Zoom", 90); sheet->querySubObject("PageSetup")->setProperty("Orientation", xlLandscape); sheet->querySubObject("PageSetup")->setProperty("PrintQuality", 600); }
KGzipFilter::Result KGzipFilter::compress_(bool finish) { Q_ASSERT(d->compressed); Q_ASSERT(d->mode == QIODevice::WriteOnly); Bytef *p = d->zStream.next_in; ulong len = d->zStream.avail_in; #ifdef DEBUG_GZIP qDebug() << " calling deflate with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable(); #endif const int result = deflate(&d->zStream, finish ? Z_FINISH : Z_NO_FLUSH); if (result != Z_OK && result != Z_STREAM_END) { //qDebug() << " deflate returned " << result; } if (d->headerWritten) { //qDebug() << "Computing CRC for the next " << len - d->zStream.avail_in << " bytes"; d->crc = crc32(d->crc, p, len - d->zStream.avail_in); } KGzipFilter::Result callerResult = result == Z_OK ? KFilterBase::Ok : (Z_STREAM_END ? KFilterBase::End : KFilterBase::Error); if (result == Z_STREAM_END && d->headerWritten && !d->footerWritten) { if (d->zStream.avail_out >= 8 /*footer size*/) { //qDebug() << "finished, write footer"; writeFooter(); } else { // No room to write the footer (#157706/#188415), we'll have to do it on the next pass. //qDebug() << "finished, but no room for footer yet"; callerResult = KFilterBase::Ok; } } return callerResult; }
void BinaryWriterAppender::closeWriter() { // Q_ASSERT_X(, "BinaryWriterAppender::closeWriter()", "Lock must be held by caller") if (!mpWriter) return; writeFooter(); mpWriter = 0; }
void Log::closeFile() { writeFooter(); file->close(); delete fileStream; delete file; delete consoleStream; }
void SRCwriter::writeFile() { writeHeader(); writeBody(); writeFooter(); ofstream file(url); file << header; file << body; file << footer; file.close(); }
MStatus polyExporter::writer(const MFileObject& file, const MString& /*options*/, MPxFileTranslator::FileAccessMode mode) //Summary: saves a file of a type supported by this translator by traversing // the all or selected objects (depending on mode) in the current // Maya scene, and writing a representation to the given file //Args : file - object containing the pathname of the file to be written to // options - a string representation of any file options // mode - the method used to write the file - export, or export active // are valid values; method will fail for any other values //Returns: MStatus::kSuccess if the export was successful; // MStatus::kFailure otherwise { #if defined (OSMac_) char nameBuffer[MAXPATHLEN]; strcpy (nameBuffer, file.fullName().asChar()); const MString fileName(nameBuffer); #else const MString fileName = file.fullName(); #endif ofstream newFile(fileName.asChar(), ios::out); if (!newFile) { MGlobal::displayError(fileName + ": could not be opened for reading"); return MS::kFailure; } newFile.setf(ios::unitbuf); writeHeader(newFile); //check which objects are to be exported, and invoke the corresponding //methods; only 'export all' and 'export selection' are allowed // if (MPxFileTranslator::kExportAccessMode == mode) { if (MStatus::kFailure == exportAll(newFile)) { return MStatus::kFailure; } } else if (MPxFileTranslator::kExportActiveAccessMode == mode) { if (MStatus::kFailure == exportSelection(newFile)) { return MStatus::kFailure; } } else { return MStatus::kFailure; } writeFooter(newFile); newFile.flush(); newFile.close(); MGlobal::displayInfo("Export to " + fileName + " successful!"); return MS::kSuccess; }
void DrawingReport::makeReport() { uint written = 0; QString category = "", vcat; currentRow = pageStartRow = currentPage = 1; sheet = openDocument(); excel->querySubObject("ActiveWindow")->setProperty("Zoom", 85); const double widths[] = { 6.29, 30.29, 11.14, 18.71, 12.29, 14.71 }; for(uint i = 0; i < sizeof(widths)/sizeof(*widths); ++i) { sheet->querySubObject("Columns(const QString&)", QString("%1:%1").arg(QString('A' + i))) ->setProperty("ColumnWidth", widths[i]); } while(query->next()) { vcat = query->value(0).toString(); if(currentRow == 1 || category != vcat || written == 16) { if(currentRow > 1) writeFooter(written); category = vcat; writeHeader(category, query->value(1).toDate()); written = 0; } writeLine(written++); } writeFooter(written); sheet->querySubObject("PageSetup")->setProperty("Zoom", 89); sheet->querySubObject("PageSetup")->setProperty("PrintQuality", 600); }
void BOSHConnectionPool::close() { if (!sid.empty()) { writeFooter(); } else { pendingTerminate = true; std::vector<BOSHConnection::ref> connectionCopies = connections; foreach (BOSHConnection::ref connection, connectionCopies) { if (connection) { connection->disconnect(); } } } }
////////////////////////////////////////////////////////////////////////////////////////// // RtfWriter::close() //! Appends the RTF footer and closes the writer //! //! \throw wtl::logic_error - [Debug only] Writer has been closed //! \throw wtl::domain_error - I/O error occurred ////////////////////////////////////////////////////////////////////////////////////////// void close() { // Check stream is open if (Closed) throw wtl::logic_error(HERE, "Writer is closed"); // Writer footer writeFooter(); // Flush+Close output flush(); Stream.close(); Closed = true; }
void ResourceCompressor::compress(const std::string &outputFile, bool verbose) { openStream(outputFile); int offset = writeHeader(); for (Entries::iterator i = entries.begin(); i != entries.end(); i++) { Entry &e = *i; compressEntry(e, offset); if (verbose) showEntryStat(e); } writeFooter(offset); closeStream(); }
void DimBuilder::writeOutput(std::ostream& out) { writeHeader(out); out << "\n"; writeIds(out); out << "\n"; writeDescriptions(out); out << "\n"; writeNameToId(out); out << "\n"; writeIdToName(out); out << "\n"; writeTypes(out); out << "\n"; writeFooter(out); }
bool CityGMLWriter::write_CityGMLSolids(int buildLoD) { /*Write the building solids to the CityGML file*/ if (open(filename_0ext+"_SLD")) { // Open and Check if open writeHeader(); writeGeometryHeader(0,0); writeGeometrySLD(exPolVector ,buildLoD); //if (has_BuildInstalls) writeGeometrySLD(biPolVector ,3,true); //if (has_BuildParts) writeGeometrySLD(bpPolVector ,3); //if (has_LoD4Rooms) writeGeometrySLD(lod4PolVector ,4); writeGeometryFooter(0); writeFooter(); gml_ofstream.close(); // Close file return true; } else std::cerr << "ERROR: Can't open file: " << filename_0ext << ".gml" <<std::endl; return false; }
virtual void report(Results *results, ostream &out) { writeHeader(out); out << endl << endl; writeSummary(out, *results); out << endl << endl; vector<Violation> violationSet = results->allViolations(); for (int index = 0, numberOfViolations = violationSet.size(); index < numberOfViolations; index++) { writeViolation(out, violationSet.at(index)); out << endl; } out << endl; writeFooter(out, Version::identifier()); out << endl; }
void SoGate::writeInstance(SoOutput *out) // //////////////////////////////////////////////////////////////////////// { if (! writeHeader(out, FALSE, TRUE)) { // Write type info typeField.write(out, "type"); const SoFieldData *fieldData = getFieldData(); if (fieldData != NULL) fieldData->write(out, this); writeFooter(out); } }
KGzipFilter::Result KGzipFilter::compress( bool finish ) { Q_ASSERT ( d->compressed ); Q_ASSERT ( d->mode == QIODevice::WriteOnly ); Bytef* p = d->zStream.next_in; ulong len = d->zStream.avail_in; int result = deflate(&d->zStream, finish ? Z_FINISH : Z_NO_FLUSH); if ( d->headerWritten ) { //kDebug(7005) << "Computing CRC for the next " << len - d->zStream.avail_in << " bytes"; d->crc = crc32(d->crc, p, len - d->zStream.avail_in); } if ( result == Z_STREAM_END && d->headerWritten ) { //kDebug(7005) << "KGzipFilter::compress finished, write footer"; writeFooter(); } return ( result == Z_OK ? KFilterBase::Ok : ( result == Z_STREAM_END ? KFilterBase::End : KFilterBase::Error ) ); }
int main(int argc, const char *argv[]) { ofstream out; out.open("castel.tex"); double px[DEGREE+1]= {20, 100, 900, 1100}; double py[DEGREE+1]= {20, 500, 500, 200}; double u= 2.0/3.0; int step= 500; writeHeader(out, px, py); writeBezier(out, step, px, py); writeLines(out, u, px, py); writeBP(out, u, px, py); writeFooter(out); if (out.is_open()) { out.close(); } return 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; }
int main(int argc, char* argv[]){ //float beta; //int row,col; string file_name = FILE_NAME; HostMatrix<float> X; HostMatrix<float> X_test; HostMatrix<float> Y; HostMatrix<float> Y_test; HostMatrix<float> Input; HostMatrix<float> Target; std::map<string,int> Classes; std::map<int,string> ClassesLookup; readFile(file_name,Input,Target,Classes,ClassesLookup); int kfold = 1; int correct_instances = 0; int incorrect_instances = 0; int total_instances = 0; int **confusionMatrix; confusionMatrix = (int**) malloc(sizeof(int*)*Classes.size()); for(int i = 0; i < (int)Classes.size(); i++){ confusionMatrix[i] = (int*) malloc(sizeof(int)*Classes.size()); memset(confusionMatrix[i],0,sizeof(int)*Classes.size()); } float Pet_mean = 0; float Ped_mean = 0; unsigned int seed = (unsigned)time(0); /***************RUN INFORMATION*************/ writeHeader(Input,Classes.size(),seed); /*******************************************/ if(!InitCUDA()) { return 1; } culaStatus status; status = culaInitialize(); std::cout << "Starting " << std::endl; float center_time = 0; float width_time = 0; float weight_time = 0; float scaling_time = 0; unsigned int time_total = 0; unsigned int testing_time = 0; unsigned int training_time = 0; clock_t initialTimeTotal = clock(); do{ X = crossvalidationTrain(Input,KFOLDS,kfold); X_test = crossvalidationTest(Input,KFOLDS,kfold); Y = crossvalidationTrain(Target,KFOLDS,kfold); Y_test = crossvalidationTest(Target,KFOLDS,kfold); HostMatrix<float> Weights; HostMatrix<float> Centers; /*Train Network*/ clock_t initialTime = clock(); RadialBasisFunction RBF(NETWORK_SIZE,RNEIGHBOURS,SCALING_FACTOR,Classes.size()); RBF.SetSeed(seed); RBF.Train(X,Y); training_time = (clock() - initialTime); center_time += RBF.times[0]; width_time += RBF.times[1]; weight_time += RBF.times[2]; scaling_time += RBF.times[3]; /*Test Network*/ initialTime = clock(); std::cout << "Testing" << std::endl; HostMatrix<float> out_test; out_test = RBF.Test(X_test); for(int i = 0; i< X_test.Rows();i++){ float max = 0; float out_class = 0; for(int j = 0; j < (int) Classes.size(); j++){ if(out_test(i,j) > max){ out_class = (float)j; max = out_test(i,j); } } out_test(i,0) = out_class+1; } for (int i = 0; i < out_test.Rows(); i++) { out_test(i,0) = (float)round(out_test(i,0)); if(out_test(i,0) <= 0) out_test(i,0) = 1; if(out_test(i,0) > Classes.size()) out_test(i,0) = (float)Classes.size(); std::cout << Y_test(i,0) << " " << out_test(i,0) << std::endl; } correct_instances += out_test.Rows() - error_calc(Y_test,out_test); incorrect_instances += error_calc(Y_test,out_test); total_instances += out_test.Rows(); /*Add values to Confusion Matrix*/ for(int i = 0; i < Y_test.Rows(); i++){ confusionMatrix[((int)Y_test(i,0))-1][((int)out_test(i,0))-1] = confusionMatrix[((int)Y_test(i,0))-1][((int)out_test(i,0))-1] + 1; } testing_time = (clock() - initialTime); /*Increment fold number, for use in crossvalidation*/ kfold++; }while(kfold <= KFOLDS); time_total = (clock() - initialTimeTotal); /*****************MEASURES****************/ measures(correct_instances,total_instances,incorrect_instances,confusionMatrix,Classes,ClassesLookup); writeFooter(center_time,width_time,weight_time,scaling_time,training_time,testing_time,time_total); culaShutdown(); cudaThreadExit(); return 0; }
bool PdfExport::createPdf(String uri, GList* range) { XOJ_CHECK_TYPE(PdfExport); if (range == NULL) { this->lastError = "No pages to export!"; return false; } if (!this->writer->openFile(uri.c_str())) { return false; } this->writer->write("%PDF-1.4\n"); int count = 0; for (GList* l = range; l != NULL; l = l->next) { PageRangeEntry* e = (PageRangeEntry*) l->data; count += e->getLast() - e->getFirst(); } if (this->progressListener) { this->progressListener->setMaximumState(count * 2); } int c = 0; for (GList* l = range; l != NULL; l = l->next) { PageRangeEntry* e = (PageRangeEntry*) l->data; for (int i = e->getFirst(); i < e->getLast(); i++) { PageRef page = doc->getPage(i); cPdf.drawPage(page); if (this->progressListener) { this->progressListener->setCurrentState(c++); } } } cPdf.finalize(); addPopplerDocument(cPdf.getDocument()); for (int i = 0; i < count; i++) { if (!writePage(i)) { g_warning("error writing page %i", i + 1); return false; } if (this->progressListener) { this->progressListener->setCurrentState(i + count); } } // Write our own footer if (!writeFooter()) { g_warning("error writing footer"); return false; } this->writer->close(); return true; }
bool PdfExport::createPdf(String uri) { XOJ_CHECK_TYPE(PdfExport); if (doc->getPageCount() < 1) { lastError = "No pages to export!"; return false; } if (!this->writer->openFile(uri.c_str())) { return false; } this->writer->write("%PDF-1.4\n"); if (this->progressListener) { this->progressListener->setMaximumState(doc->getPageCount() * 2); } int count = doc->getPageCount(); for (int i = 0; i < count; i++) { PageRef page = doc->getPage(i); cPdf.drawPage(page); if (this->progressListener) { this->progressListener->setCurrentState(i); } } cPdf.finalize(); addPopplerDocument(cPdf.getDocument()); for (int i = 0; i < count; i++) { if (!writePage(i)) { g_warning("error writing page %i", i + 1); return false; } if (this->progressListener) { this->progressListener->setCurrentState(i + count); } } // Write our own footer if (!writeFooter()) { g_warning("error writing footer"); return false; } this->writer->close(); return true; }
int main(int argc, char** argv) { if (argc != 6) { std::cout << "This program takes in input glad.h and outputs the include and implementation files for OSMesa OpenGL function and regular OpenGL functions." << std::endl; std::cout << "Usage: generateGLIncludes <glad.h path> <output dir path> <namespace name> <baseFileName> <inlcude glad debug symbols>" << std::endl; std::cout << "Example: generateGLIncludes /Users/alexandre/development/Natron/Global/gladRel/include/glad/glad.h /Users/alexandre/development/Natron/Engine Natron OSGLFunctions 1" << std::endl; return 1; } QFile f(argv[1]); if ( !f.open(QIODevice::ReadOnly) ) { std::cout << "Could not open " << argv[1] << std::endl; return 1; } // Check that output path exists QDir outputDir(argv[2]); if ( !outputDir.exists() ) { std::cout << argv[2] << " does not seem to be a valid directory" << std::endl; return 1; } QString namespaceName(argv[3]); QString baseFilename(argv[4]); bool supportGladDebug; { QString supportDebugSymbolsStr(argv[5]); supportGladDebug = (bool)supportDebugSymbolsStr.toInt(); } QString absoluteDirPath = outputDir.absolutePath(); QString outputHeaderFilename = absoluteDirPath + "/" + baseFilename + ".h"; QFile of_header(outputHeaderFilename); if ( !of_header.open(QIODevice::WriteOnly) ) { std::cout << "Could not open " << outputHeaderFilename.toStdString() << std::endl; return 1; } QTextStream ots_header(&of_header); QTextStream its(&f); QString definesStr; std::list<FunctionSignature> signatures; QString functionTypedefsStr; QString prevLine; while ( !its.atEnd() ) { // Read each line of glad.h QString line = its.readLine(); { // Search for a define QString toFind = "#define GL_"; int found = line.indexOf(toFind); if (found != -1) { definesStr += line; definesStr += "\n"; } } // Search for a function QString typedefToken("typedef "); QString pfnToken("(APIENTRYP PFNGL"); int foundFuncDef = line.indexOf(typedefToken); int foundPNFToken = line.indexOf(pfnToken); if ( (foundFuncDef != -1) && (foundPNFToken != -1) ) { int pos = foundPNFToken + pfnToken.size(); int foundFirstEndParenthesis = line.indexOf(')', pos); assert(foundFirstEndParenthesis != -1); FunctionSignature signature; QString lastFuncNameCaps = line.mid(pos, foundFirstEndParenthesis - pos); signature.signature = line.mid(foundFirstEndParenthesis); // "near" and "far" are defined as macros in windows.h signature.signature.replace("GLdouble near, GLdouble far", "GLdouble nearVal, GLdouble farVal"); signature.returnType = line.mid( foundFuncDef + typedefToken.size(), foundPNFToken - 1 - ( foundFuncDef + typedefToken.size() ) ); QString funcTypeDefStr = "typedef "; funcTypeDefStr += signature.returnType; funcTypeDefStr += " (*PFNGL"; funcTypeDefStr += lastFuncNameCaps; funcTypeDefStr += signature.signature; funcTypeDefStr += "\n"; functionTypedefsStr += funcTypeDefStr; // Remove the extraneous ; at the end of the signature // Also remove the prepending ) signature.signature.remove(0, 1); signature.signature.remove(signature.signature.size() - 1, 1); signature.funcPNType = "PFNGL"; signature.funcPNType += lastFuncNameCaps; // extract parameters { int i = 1; // start after the leading ( while ( i < signature.signature.size() ) { QString param; while ( signature.signature[i] != QChar(',') && signature.signature[i] != QChar(')') ) { param.append(signature.signature[i]); ++i; } // Now only keep the name of the parameter { int j = param.size() - 1; while ( j >= 0 && param[j].isLetterOrNumber() ) { --j; } param = param.mid(j + 1); } signature.parameters.append(param); assert( signature.signature[i] == QChar(',') || signature.signature[i] == QChar(')') ); ++i; // bypass last character if ( signature.signature[i] == QChar(')') ) { break; } } } // we caught a function typedef before, we expect to read the following #define glXxxx function with the appropriate case // in release glad.h, the next line is of the type GLAPI PFNGLCOLOR4FVPROC glad_glColor4fv; // the line after that is the one we want #define glColor4fv glad_glColor4fv line = its.readLine(); assert( !its.atEnd() ); line = its.readLine(); QString toFind("#define gl"); int foundDefine = line.indexOf(toFind); if (foundDefine == -1) { std::cout << "Parser failed to find #define glXXX statement 2 lines after a function typedef, make sure that you are running this program against a release version of glad.h" << std::endl; return 1; } // Check that this is the same symbol // Remove the PROC at the end of the func def lastFuncNameCaps.remove("PROC"); int checkIndex = toFind.size(); QString symbolStart = line.mid(checkIndex); assert( symbolStart.startsWith(lastFuncNameCaps, Qt::CaseInsensitive) ); { int i = 8; // start on the g //extract the function name while ( i < line.size() && line.at(i) != QChar(' ') ) { signature.funcName.push_back( line.at(i) ); ++i; } } signatures.push_back(signature); } // if (foundFuncDef != -1 && foundPNFToken != -1) { prevLine = line; } writeHeader(ots_header); writePODs(ots_header); ots_header << definesStr << "\n" "\n"; ots_header << functionTypedefsStr << "\n" "\n"; writeStartClass(namespaceName, ots_header); // Define the singleton ots_header << " static OSGLFunctions<USEOPENGL>& getInstance()\n" " {\n" " static OSGLFunctions<USEOPENGL> instance;\n" "\n" " return instance;\n" " }\n" "\n" " // load function, implemented in _gl.h and _mesa.h\n" " void load_functions();\n" "\n" " // private constructor\n" " OSGLFunctions() { load_functions(); }\n" "\n"; // Declare member functions for (std::list<FunctionSignature>::iterator it = signatures.begin(); it != signatures.end(); ++it) { ots_header << " " << it->funcPNType << " _" << it->funcName << ";\n"; } ots_header << "\n"; ots_header << "public:\n" "\n"; ots_header << " // static non MT-safe load function that must be called once to initialize functions\n" " static void load()\n" " {\n" " (void)getInstance();\n" " }\n" "\n" " static bool isGPU()\n" " {\n" " return USEOPENGL;\n" " }\n"; for (std::list<FunctionSignature>::iterator it = signatures.begin(); it != signatures.end(); ++it) { QString lineStart = " static " + it->returnType + " " + it->funcName; QString indentedSig = it->signature; indentedSig.replace( ", ", ",\n" + QString(lineStart.size() + 1, ' ') ); ots_header << "\n" << lineStart << indentedSig << "\n" " {\n"; if (it->returnType == "void") { ots_header << " "; } else { ots_header << " return "; } ots_header << "getInstance()._" << it->funcName << "("; QStringList::const_iterator next = it->parameters.begin(); if ( !it->parameters.isEmpty() ) { ++next; } for (QStringList::const_iterator it2 = it->parameters.begin(); it2 != it->parameters.end(); ++it2) { ots_header << *it2; if ( next != it->parameters.end() ) { ots_header << ", "; ++next; } } ots_header << ");\n" " }\n"; } writeEndClass(namespaceName, ots_header); writeFooter(ots_header); writeImplementationCppFile(namespaceName, baseFilename, signatures, absoluteDirPath, "gl", true, supportGladDebug); writeImplementationCppFile(namespaceName, baseFilename, signatures, absoluteDirPath, "mesa", false, supportGladDebug); return 0; } // main
// // Maya calls this method to have the translator write out a file. // MStatus maTranslator::writer( const MFileObject& file, const MString& /* options */, MPxFileTranslator::FileAccessMode mode ) { // // For simplicity, we only do full saves/exports. // if ((mode != kSaveAccessMode) && (mode != kExportAccessMode)) return MS::kNotImplemented; // // Let's see if we can open the output file. // fstream output(file.fullName().asChar(), ios::out | ios::trunc); if (!output.good()) return MS::kNotFound; // // Get some node flags to keep track of those nodes for which we // have already done various stages of processing. // MStatus status; fCreateFlag = MFnDependencyNode::allocateFlag(fPluginName, &status); if (status) fAttrFlag = MFnDependencyNode::allocateFlag(fPluginName, &status); if (status) fConnectionFlag = MFnDependencyNode::allocateFlag(fPluginName, &status); if (!status) { MGlobal::displayError( "Could not allocate three free node flags." " Try unloading some other plugins." ); return MS::kFailure; } // // Run through all of the nodes in the scene and clear their flags. // MItDependencyNodes nodesIter; for (; !nodesIter.isDone(); nodesIter.next()) { MObject node = nodesIter.item(); MFnDependencyNode nodeFn(node); nodeFn.setFlag(fCreateFlag, false); nodeFn.setFlag(fAttrFlag, false); nodeFn.setFlag(fConnectionFlag, false); } // // Write out the various sections of the file. // writeHeader(output, file.name()); writeFileInfo(output); writeReferences(output); writeRequirements(output); writeUnits(output); writeDagNodes(output); writeNonDagNodes(output); writeDefaultNodes(output); writeReferenceNodes(output); writeConnections(output); writeFooter(output, file.name()); output.close(); MFnDependencyNode::deallocateFlag(fPluginName, fCreateFlag); return MS::kSuccess; }
void ClusterEditingOutput::write() { if(verbosity > 3) { cout << "=========================" << endl; cout <<"solutions:"<<endl; cout<<"-------------------------"<<endl; } for(size_t i = 0; i < _solutions.getNumberOfSolutions(); i++) { openStream(i); double insertionCost = 0.0, deletionCost = 0.0; int deletionCount = 0, insertionCount = 0; size_t numberOfNodes = countNodes(_instance.getWorkingCopyInstance().getGraph()); writeHeader(_label, i, numberOfNodes, _solutions.getNumberOfClusters(i)); writeBeginNodes(numberOfNodes); if(verbosity > 3) { cout <<endl<< "=========================" << endl; cout << "=========================" << endl<<endl; cout <<"solution no "<<i+1<<":" <<endl; cout << "=========================" << endl; cout << "partition:" << endl; cout <<"-------------------------" << endl; } for(size_t k = 0; k < _solutions.getNumberOfClusters(i); k++) { if(verbosity > 3) cout<<"cluster no "<<k+1<<":"<<endl<<"\t"; writeBeginCluster(k); int clusterSize = _solutions.getCluster(i, k).size(); int currentNodeIndex = 0; for(vector<int>::iterator it = _solutions.getCluster(i, k).begin(); it != _solutions.getCluster(i, k).end(); it++,currentNodeIndex ++) { FullGraph::Node u = _instance.getOrig().nodeFromId(*it); if(verbosity > 3) { cout <<_instance.getNodeName(u)<<" "; } writeNode(*it, _instance.getNodeName(u), k,(currentNodeIndex == clusterSize-1) ? true : false); } if(verbosity > 3) { cout <<endl; } writeEndCluster(k == (_solutions.getNumberOfClusters(i)-1) ? true : false); } writeEndNodes(); writeBeginEdges(); if (verbosity > 3) { cout << "=========================" << endl; cout << "modifications:" << endl; cout<<"-------------------------"<<endl; } for(size_t k = 0; k < _solutions.getNumberOfClusters(i); k++) { //internal vector<int>& v = _solutions.getCluster(i, k); for(vector<int>::size_type l = 0; l < v.size(); l++) { FullGraph::Node x = _instance.getOrig().nodeFromId(v[l]); for(std::vector<int>::size_type j = l+1; j < v.size(); j++) { FullGraph::Node y = _instance.getOrig().nodeFromId(v[j]); FullGraph::Edge xy = _instance.getOrig().edge(x, y); double weight = _instance.getWeight(xy); string name = _instance.getEdgeName(xy); int sourceId = v[l]; int targetId = v[j]; if(weight <= 0) { if (verbosity > 3) cout << "insertion of edge " << name << " (cost " << abs(weight) << ")" << endl; insertionCost+= abs(weight); insertionCount++; writeEdge(sourceId, targetId, name, weight, true); } else { writeEdge(sourceId, targetId, name, weight, false); } } } //external for(vector<vector<int> >::size_type l = k+1; l < _solutions.getSolution(i).size(); l++) { vector<int>& w = _solutions.getCluster(i, l); for(vector<int>::size_type i = 0; i < v.size(); i++) { FullGraph::Node x = _instance.getOrig().nodeFromId(v[i]); for(std::vector<int>::size_type j = 0; j < w.size(); j++) { FullGraph::Node y = _instance.getOrig().nodeFromId(w[j]); FullGraph::Edge xy = _instance.getOrig().edge(x, y); double weight = _instance.getWeight(xy); string name = _instance.getEdgeName(xy); int sourceId = v[i]; int targetId = w[j]; if(weight > 0) { if (verbosity > 3) cout << "deletion of edge " << name << " (cost " << abs(weight) << ")" << endl; deletionCost+= abs(weight); deletionCount++; writeEdge(sourceId, targetId, name, weight, true); } } } } } writeEndEdges(); if (verbosity > 3) { cout << "----------------------------------" << endl; cout <<"total insertion cost ("<< insertionCount<<" insertions):\t"<<insertionCost<<endl; cout <<"total deletion cost ("<<deletionCount<<" deletions):\t"<<deletionCost<<endl; cout <<"=================================="<<endl; cout <<"total cost ("<<insertionCount+deletionCount<<" modifications):\t"<<insertionCost+deletionCost<<endl; } writeFooter(); closeStream(); } }
void SoSwitch::write(SoWriteAction *action) // //////////////////////////////////////////////////////////////////////// { SoOutput *out = action->getOutput(); // When writing out a switch that is in a path, we always want to // write out ALL children of the switch. If we did the default // thing of writing out just those children that affect the nodes // in the path, we could screw up. Consider a switch that has two // child separators and whichChild set to 1. If a path goes // through the switch to the second child, the first child, being // a separator, does not affect the path. But if we don't write // out the separator, the whichChild will reference a // nonexistent child. So we always write out all children. // NOTE: SoChildList::traverse() checks the current path code and // skips children off the path that do not affect the // state. Because of this we have to avoid calling it. Instead, we // do its work here. // This code is stolen and modified from SoGroup::write() and // SoChildList::traverse() int lastChild = getNumChildren() - 1; SoAction::PathCode pc = action->getCurPathCode(); // In write-reference counting phase if (out->getStage() == SoOutput::COUNT_REFS) { // Increment our write reference count addWriteReference(out); // If this is the first reference (i.e., we don't now have // multiple references), also count all appropriate children if (! hasMultipleWriteRefs()) { for (int i = 0; i <= lastChild; i++) { action->pushCurPath(i); action->traverse(getChild(i)); action->popCurPath(pc); } } } // In writing phase, we have to do some more work else if (! writeHeader(out, TRUE, FALSE)) { // Write fields const SoFieldData *fieldData = getFieldData(); fieldData->write(out, this); // We KNOW that all children should be written, so don't // bother calling shouldWrite() // If writing binary format, write out number of children // that are going to be written if (out->isBinary()) out->write(getNumChildren()); for (int i = 0; i <= lastChild; i++) { action->pushCurPath(i); action->traverse(getChild(i)); action->popCurPath(pc); } // Write post-children stuff writeFooter(out); } }