bool wxEncodingConverter::Convert(const wchar_t* input, wchar_t* output) const { wxASSERT_MSG(m_UnicodeOutput, wxT("You cannot convert to 8-bit if output is const wchar_t*!")); wxASSERT_MSG(m_UnicodeInput, wxT("You cannot convert from 8-bit if input is const wchar_t*!")); const wchar_t *i; wchar_t *o; if (m_JustCopy) { // wcscpy() is not guaranteed to exist for (i = input, o = output; *i != 0;) *(o++) = (*(i++)); *o = 0; return true; } wxCHECK_MSG(m_Table != NULL, false, wxT("You must call wxEncodingConverter::Init() before actually converting!")); bool replaced = false; for (i = input, o = output; *i != 0;) *(o++) = (wchar_t)(GetTableValue(m_Table, (wxUint8)*(i++), replaced)); *o = 0; return !replaced; }
bool wxEncodingConverter::Convert(const wchar_t* input, char* output) const { wxASSERT_MSG(!m_UnicodeOutput, wxT("You cannot convert to unicode if output is const char*!")); wxASSERT_MSG(m_UnicodeInput, wxT("You cannot convert from 8-bit if input is const wchar_t*!")); const wchar_t *i; char *o; if (m_JustCopy) { for (i = input, o = output; *i != 0;) *(o++) = (char)(*(i++)); *o = 0; return true; } wxCHECK_MSG(m_Table != NULL, false, wxT("You must call wxEncodingConverter::Init() before actually converting!")); bool replaced = false; for (i = input, o = output; *i != 0;) *(o++) = (char)(GetTableValue(m_Table, (wxUint16)*(i++), replaced)); *o = 0; return !replaced; }
const unsigned short DataManager::SetLabel(const QColor &color) { // labelvalues usually goes 0-n, that's n+1 values = m_labelValues.size(); auto newlabel = ObjectVector.size(); // we need to find an unused scalar value in our table bool free = false; auto freevalue = m_firstFreeValue; while (!free) { free = true; // can't use find() as the value we're searching is the 'second' field for (auto it: ObjectVector) { if (it.second->scalar == freevalue) { free = false; freevalue++; } } } auto object = std::make_shared<ObjectInformation>(); object->scalar = freevalue; object->size = 0; object->centroid = Vector3d{0, 0, 0}; object->min = Vector3ui{0, 0, 0}; object->max = Vector3ui{0, 0, 0}; ObjectVector.insert(std::pair<unsigned short, std::shared_ptr<ObjectInformation>>(newlabel, object)); m_actionsBuffer->storeObject(std::pair<unsigned short, std::shared_ptr<ObjectInformation>>(newlabel, object)); auto temptable = vtkSmartPointer<vtkLookupTable>::New(); CopyLookupTable(m_lookupTable, temptable); // this is a convoluted way of doing things, but SetNumberOfTableValues() seems to // corrupt the table (due to reallocation?) and all values must be copied again. m_lookupTable->SetNumberOfTableValues(newlabel + 1); double rgba[4]; for (int index = 0; index != temptable->GetNumberOfTableValues(); index++) { temptable->GetTableValue(index, rgba); m_lookupTable->SetTableValue(index, rgba); } m_lookupTable->SetTableValue(newlabel, color.redF(), color.greenF(), color.blueF(), DIM_ALPHA); m_lookupTable->SetTableRange(0, newlabel); m_lookupTable->Modified(); return newlabel; }
void DataManager::GenerateLookupTable() { // compute vtkLookupTable colors for labels, first color is black for background // rest are pre-calculated by Build() based on the number of labels double rgba[4]{ 0.05, 0.05, 0.05, HIGHLIGHT_ALPHA }; auto labels = m_labelMap->GetNumberOfLabelObjects(); Q_ASSERT(0 != labels); m_lookupTable->Allocate(); m_lookupTable->SetNumberOfTableValues(labels + 1); m_lookupTable->SetTableRange(0, labels); m_lookupTable->SetTableValue(0, rgba); auto temporal_table = vtkSmartPointer<vtkLookupTable>::New(); temporal_table->SetNumberOfTableValues(labels); temporal_table->SetRange(0, labels-1); temporal_table->Build(); for (unsigned int index = 0; index < labels; ++index) { temporal_table->GetTableValue(index, rgba); m_lookupTable->SetTableValue(index + 1, rgba[0], rgba[1], rgba[2], DIM_ALPHA); } }
void PressureTable::WriteTable(string output) { FILE *inFp = 0; char filename[kStrLong], buffer_m[kStrMed]; size_t dum; if (mpi_rank == 0) cout << endl << "***** Write table to file *****" << endl << endl; // *************** // Open table file // *************** if (output == "debug") cout << "Opening file "<< TableFilename << endl; TableFilename.copy(&filename[0], kStrLong); dum = TableFilename.size(); if (dum < kStrLong) { strcpy(&filename[dum], "\0"); } else { cerr << "### Chemistry table file name is too long! ###" << endl; throw(-1); } if (!(inFp = fopen(filename, "wb"))) { cerr << "### Could not open chemistry table file " << filename << " ###" << endl; throw(-1); } // ************************ // Write table general info // ************************ // Version if (output == "debug") cout << "Write version " << version <<endl; dum = fwrite(&version, sizeof(double), 1, inFp); if (dum != 1) { cerr << "### Error writing file: version ###" << endl; throw(-1); } // CombustionModel if (output == "debug") cout << "Write model " << CombustionModel << endl; CombustionModel.copy(&buffer_m[0], kStrMed); dum = CombustionModel.size(); if (dum < kStrMed) {strcpy(&buffer_m[dum], "\0");} else { cerr << "### Combustion model name is too long! ###" << endl; throw(-1); } dum = fwrite(&buffer_m[0], sizeof(char), kStrMed, inFp); if (dum != kStrMed) { cerr << "### Error writing file: Combustion model ###" << endl; throw(-1);} // ChemTableType if (output == "debug") cout << "Write ChemTableType " << ChemTableType << endl; ChemTableType.copy(&buffer_m[0], kStrMed); dum = ChemTableType.size(); if (dum < kStrMed) { strcpy(&buffer_m[dum], "\0"); } else { cerr << "### Chem Table type is too long! ###" << endl; throw(-1); } dum = fwrite(&buffer_m[0], sizeof(char), kStrMed, inFp); if (dum != kStrMed) {cerr << "### Error writing file: Chem Table type ###" << endl; throw(-1);} // ********************** // Write table dimensions // ********************** int nPress = GetDimension1(); if (output == "debug") cout << "Write nPress "<< nPress << endl; dum = fwrite(&nPress, sizeof(int), 1, inFp); if (dum != 1) { cerr << "### Error writing file: nPress ###" << endl; throw(-1); } int nZm = GetDimension2(); if (output == "debug") cout << "Write nZm "<< nZm << endl; dum = fwrite(&nZm, sizeof(int), 1, inFp); if (dum != 1) { cerr << "### Error writing file: nZm ###" << endl; throw(-1); } int nZv = GetDimension3(); if (output == "debug") cout << "Write nZv "<< nZv << endl; dum = fwrite(&nZv, sizeof(int), 1, inFp); if (dum != 1) { cerr << "### Error writing file: nZv ###" << endl; throw(-1); } int nC = GetDimension4(); if (output == "debug") cout << "Write nC "<< nC << endl; dum = fwrite(&nC, sizeof(int), 1, inFp); if (dum != 1) { cerr << "### Error writing file: nC ###" << endl; throw(-1); } int nVar = GetNumberVariables(); if (output == "debug") cout << "Write nVar "<< nVar << endl; dum = fwrite(&nVar, sizeof(int), 1, inFp); if (dum != 1) { cerr << "### Error writing file: nVar ###" << endl; throw(-1);} // *********************** // Write table coordinates // *********************** if (output == "debug") cout << "Write Pressure vector "<< endl; double *Pressure = new double[nPress]; CopyCoordinate1(Pressure); dum = fwrite(Pressure, sizeof(double), nPress, inFp); if (dum != nPress) { cerr << "### Error writing file: Pressure ###" << endl; throw(-1);} if (output == "debug") cout << "Write Zm vector "<< endl; double *Zm = new double[nZm]; CopyCoordinate2(Zm); dum = fwrite(Zm, sizeof(double), nZm, inFp); if (dum != nZm) { cerr << "### Error writing file: Zm ###" << endl; throw(-1);} if (output == "debug") cout << "Write Zv vector "<< endl; double *Zv = new double[nZv]; CopyCoordinate3(Zv); dum = fwrite(Zv, sizeof(double), nZv, inFp); if (dum != nZv) { cerr << "### Error writing file: Zv ###" << endl; throw(-1);} if (output == "debug") cout << "Write C vector "<< endl; double *CC = new double[nC]; CopyCoordinate4(CC); dum = fwrite(CC, sizeof(double), nC, inFp); if (dum != nC) { cerr << "### Error writing file: CC ###" << endl; throw(-1);} // *********************** // Write name of variables // *********************** for (int l = 0; l < nVar; l++) { if (output == "debug") cout << "Write VarName "<< VarNames[l] << endl; VarNames[l].copy(&buffer_m[0], kStrMed); dum = VarNames[l].size(); if (dum < kStrMed) {strcpy(&buffer_m[dum], "\0");} else { cerr << "### Variable name " << VarNames[l] << " is too long! ###" << endl; throw(-1);} dum = fwrite(&buffer_m, sizeof(char), kStrMed, inFp); if (dum != kStrMed) { cerr << "### Error writing file: Variable name " << VarNames[l] << " ###" << endl; throw(-1);} } // **************** // Write table data // **************** if (output == "debug") cout << "Write Table" << endl; for (int ipress=0; ipress <nPress; ipress++) for (int i = 0; i < nZm; i++) for (int j = 0; j < nZv; j++) for (int k = 0; k < nC; k++) for (int n = 0; n < nVar; n++) { float value = GetTableValue(ipress,i,j,k,n); dum = fwrite(&value, sizeof(float), 1, inFp); if (dum != 1) { cerr << "### Error reading file: Table -> " << ipress << " " << i << " " << j << " " << k << " " << n << " ### " << endl; throw(-1);} } // **************** // Close table file // **************** if (output == "debug") cout << "Close file" << endl; fclose(inFp); }