44 template <
class dataType,
46 int execute(
const dataType *
const inputData,
49 const triangulationType &triangulation);
52 template <
class dataType,
typename triangulationType>
54 std::vector<std::tuple<SimplexId, SimplexId, dataType>> &JTPairs,
55 std::vector<std::tuple<SimplexId, SimplexId, dataType>> &STPairs,
56 const dataType *
const inputScalars_,
58 const triangulationType &triangulation);
59 template <
typename dataType,
typename triangulationType>
61 const dataType *
const inputData,
65 const triangulationType &triangulation);
70 template <
typename dataType>
72 const dataType *
const inputData,
75 const double &tol)
const;
81 inline void setSQ(
const std::string &sqMethod) {
105 if(triangulation !=
nullptr) {
157 const std::array<double, 2> &sfRange) {
158 this->
ZFPTolerance = zfpRelTol * (sfRange[1] - sfRange[0]) / 100.0;
178 static unsigned int log2(
int val);
179 inline static bool cmp(
const std::tuple<double, int> &a,
180 const std::tuple<double, int> &b) {
181 return std::get<1>(a) > std::get<1>(b);
183 inline static bool cmp2(
const std::tuple<double, int> &a,
184 const std::tuple<double, int> &b) {
185 return std::get<1>(a) < std::get<1>(b);
188 template <
typename T>
190 static_assert(std::is_same<T, uint8_t>() || std::is_same<T, int32_t>()
191 || std::is_same<T, uint64_t>()
192 || std::is_same<T, double>(),
193 "Function should have only those types");
195 const auto status = std::fread(&ret,
sizeof(T), 1, fm);
197 this->
printErr(
"Error reading " + std::string(
typeid(T).name()) +
"!");
201 template <
typename T>
203 const auto status = std::fread(buffer,
sizeof(T), length, fm);
205 this->
printErr(
"Error reading " + std::string(
typeid(T).name())
209 template <
typename T>
210 void Write(FILE *fm, T data)
const {
211 static_assert(std::is_same<T, uint8_t>() || std::is_same<T, int32_t>()
212 || std::is_same<T, uint64_t>()
213 || std::is_same<T, double>(),
214 "Function should have only those types");
215 auto status = std::fwrite(&data,
sizeof(T), 1, fm);
217 this->
printErr(
"Error writing " + std::string(
typeid(T).name()) +
"!");
220 template <
typename T>
222 const auto status = std::fwrite(buffer,
sizeof(T), length, fm);
224 this->
printErr(
"Error writing " + std::string(
typeid(T).name())
230 std::vector<int> &segmentation,
231 int &numberOfVertices,
232 int &numberOfSegments)
const;
235 std::vector<std::tuple<double, int>> &mappings,
236 std::vector<std::tuple<double, int>> &mappingsSortedPerValue,
237 std::vector<std::tuple<int, double, int>> &constraints,
240 int &nbConstraints)
const;
243 template <
typename triangulationType>
244 int ReadFromFile(FILE *fm,
const triangulationType &triangulation);
247 const std::vector<int> &segmentation,
248 int numberOfVertices,
249 int numberOfSegments)
const;
252 std::vector<std::tuple<double, int>> &mapping,
253 std::vector<std::tuple<int, double, int>> &constraints)
const;
258 const char *sqMethod,
265 const std::string &dataArrayName);
270 const char *sqMethod,
278 const std::string &dataArrayName);
280 template <
typename dataType>
282 std::vector<std::tuple<dataType, int>> &mappings,
283 std::vector<std::tuple<dataType, int>> &mappingsSortedPerValue,
288 std::vector<int> &Seg)
const;
293 int CompressWithZFP(FILE *file,
294 const bool decompress,
295 std::vector<double> &array,
299 const double zfpTolerance)
const;
302#ifdef TTK_ENABLE_ZLIB
303 unsigned long GetZlibDestLen(
const unsigned long sourceLen)
const;
304 void CompressWithZlib(
bool decompress,
306 unsigned long &destLen,
307 const unsigned char *
const source,
308 const unsigned long sourceLen)
const;
314 int ComputeTotalSizeForOther()
const;
316 int ComputeTotalSizeForPersistenceDiagram(
317 std::vector<std::tuple<double, int>> &mapping,
318 std::vector<std::tuple<int, double, int>> &criticalConstraints,
322 double zfpTolerance)
const;
324 int ReadPersistenceTopology(FILE *fm);
325 int ReadOtherTopology(FILE *fm)
const;
326 template <
typename triangulationType>
327 int ReadPersistenceGeometry(FILE *fm,
328 const triangulationType &triangulation);
329 int ReadOtherGeometry(FILE *fm)
const;
331 int WritePersistenceTopology(FILE *fm);
332 int WriteOtherTopology(FILE *fm)
const;
333 int WritePersistenceGeometry(FILE *fm,
338 int WriteOtherGeometry(FILE *fm)
const;
340 template <
typename dataType,
typename triangulationType>
341 int PerformSimplification(
342 const std::vector<std::tuple<int, double, int>> &constraints,
346 const triangulationType &triangulation);
350 template <
typename type>
351 static type abs(
const type var) {
352 return (var >= 0) ? var : -var;
355 template <
typename type>
356 static type abs_diff(
const type var1,
const type var2) {
357 return (var1 > var2) ? var1 - var2 : var2 - var1;
412template <
class dataType,
typename triangulationType>
414 const dataType *
const inputData,
416 dataType *outputData,
417 const triangulationType &triangulation) {
418 this->
printMsg(
"Starting compression...");
421#ifndef TTK_ENABLE_KAMIKAZE
422 if(inputData ==
nullptr)
424 if(outputData ==
nullptr)
429 int const vertexNumber = triangulation.getNumberOfVertices();
437 vertexNumber, inputData, inputOffsets, outputData,
Tolerance);
442template <
typename triangulationType>
444 FILE *fp,
const triangulationType &triangulation) {
447 this->
printMsg(
"Successfully read metadata.");
449 if(ZFPOnly && ZFPTolerance < 0.0) {
450 this->
printMsg(
"Wrong ZFP absolute error tolerance for ZFP-only use.");
454 bool const useZlib = Read<uint8_t>(fp);
456 std::vector<unsigned char> ddest;
457 unsigned long destLen;
459#ifdef TTK_ENABLE_ZLIB
462 auto sl = Read<uint64_t>(fp);
463 auto dl = Read<uint64_t>(fp);
466 std::vector<unsigned char> ssource(sl);
467 ReadByteArray(fp, ssource.data(), sl);
468 this->
printMsg(
"Successfully read compressed data.");
471 ddest.resize(destLen);
473 CompressWithZlib(
true, dest, destLen, ssource.data(), sl);
474 this->
printMsg(
"Successfully uncompressed data.");
477 this->
printMsg(
"File was not compressed with ZLIB.");
480 const auto dl = Read<uint64_t>(fp);
483 ddest.resize(destLen);
485 ReadByteArray(fp, dest, destLen);
489 this->
printMsg(
" File compressed but ZLIB not installed! Aborting.");
493 this->
printMsg(
" ZLIB not installed, but file was not compressed anyways.");
496 const auto dl = Read<uint64_t>(fp);
499 ddest.resize(destLen);
501 ReadByteArray(fp, dest, destLen);
506 char *buf =
reinterpret_cast<char *
>(dest);
511 const std::string s = fileName + std::string(
".temp");
512 const char *ffn = s.c_str();
513 FILE *ftemp = fopen(ffn,
"wb");
514 fwrite(buf, destLen,
sizeof(
char), ftemp);
516 FILE *fm = fopen(ffn,
"rb");
522 ReadPersistenceTopology(fm);
524 ReadOtherTopology(fm);
527 this->
printMsg(
"Successfully read topology.");
533 status = ReadPersistenceGeometry(fm, triangulation);
535 status = ReadOtherGeometry(fm);
544 this->
printMsg(
"Successfully read geometry.");
545 this->
printMsg(
"Successfully read file.");
547 this->
printMsg(
"Failed to write (possibly ZFP)!");
548 this->
printMsg(
"File may be corrupted!");
AbstractTriangulation is an interface class that defines an interface for efficient traversal methods...
virtual int preconditionVertexNeighbors()
Minimalist debugging class.
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
TTK processing package for the topological simplification of scalar data.
int preconditionTriangulation(AbstractTriangulation *triangulation)
TTK processing package for the computation of persistence diagrams.
TTK topologicalCompression processing package.
static bool cmp2(const std::tuple< double, int > &a, const std::tuple< double, int > &b)
int ReadFromFile(FILE *fm, const triangulationType &triangulation)
int ReadPersistenceIndex(FILE *fm, std::vector< std::tuple< double, int > > &mappings, std::vector< std::tuple< double, int > > &mappingsSortedPerValue, std::vector< std::tuple< int, double, int > > &constraints, double &min, double &max, int &nbConstraints) const
void Write(FILE *fm, T data) const
std::vector< int > segmentation_
int WriteCompactSegmentation(FILE *fm, const std::vector< int > &segmentation, int numberOfVertices, int numberOfSegments) const
int ReadMetaData(FILE *fm)
std::vector< int > & getSegmentation()
std::vector< SimplexId > compressedOffsets_
bool UseTopologicalSimplification
std::vector< std::tuple< double, int > > & getMapping()
void WriteByteArray(FILE *fm, const T *buffer, size_t length) const
int compressForOther(int vertexNumber, const dataType *const inputData, const SimplexId *const inputOffsets, dataType *outputData, const double &tol) const
void relToAbsZFPTolerance(const double zfpRelTol, const std::array< double, 2 > &sfRange)
Switch from a relative (% of scalar field range) to an absolute ZFP tolerance.
int WritePersistenceIndex(FILE *fm, std::vector< std::tuple< double, int > > &mapping, std::vector< std::tuple< int, double, int > > &constraints) const
int execute(const dataType *const inputData, const SimplexId *const inputOffsets, dataType *outputData, const triangulationType &triangulation)
void setUseTopologicalSimplification(bool useTopologicalSimplification)
void setSubdivide(bool b)
void setFileName(char *fn)
int compressForPersistenceDiagram(int vertexNumber, const dataType *const inputData, const SimplexId *const inputOffset, dataType *outputData, const double &tol, const triangulationType &triangulation)
int computePersistencePairs(std::vector< std::tuple< SimplexId, SimplexId, dataType > > &JTPairs, std::vector< std::tuple< SimplexId, SimplexId, dataType > > &STPairs, const dataType *const inputScalars_, const SimplexId *const inputOffsets, const triangulationType &triangulation)
void ReadByteArray(FILE *fm, T *buffer, size_t length) const
int WriteToFile(FILE *fp, int compressionType, bool zfpOnly, const char *sqMethod, int dataType, int *dataExtent, double *dataSpacing, double *dataOrigin, double *data, double tolerance, double zfpTolerance, const std::string &dataArrayName)
int getNbVertices() const
std::vector< std::tuple< int, double, int > > & getCriticalConstraints()
void setTolerance(const double data)
const std::vector< char > & getDataArrayName() const
double getTolerance() const
static bool cmp(const std::tuple< double, int > &a, const std::tuple< double, int > &b)
std::vector< double > decompressedData_
double getZFPTolerance() const
std::vector< char > dataArrayName_
std::vector< std::tuple< int, double, int > > criticalConstraints_
double * getDataSpacing()
int getDataScalarType() const
std::vector< SimplexId > & getDecompressedOffsets()
void CropIntervals(std::vector< std::tuple< dataType, int > > &mappings, std::vector< std::tuple< dataType, int > > &mappingsSortedPerValue, double min, double max, int vertexNumber, double *array, std::vector< int > &Seg) const
void setCompressionType(int compressionType)
int ReadCompactSegmentation(FILE *fm, std::vector< int > &segmentation, int &numberOfVertices, int &numberOfSegments) const
const unsigned long formatVersion_
std::vector< std::tuple< double, int > > mapping_
int getNbSegments() const
void preconditionTriangulation(AbstractTriangulation *const triangulation)
LegacyTopologicalSimplification topologicalSimplification
int WriteMetaData(FILE *fp, int compressionType, bool zfpOnly, const char *sqMethod, int dataType, int *dataExtent, double *dataSpacing, double *dataOrigin, double tolerance, double zfpTolerance, const std::string &dataArrayName)
int getCompressionType() const
std::vector< SimplexId > & getCompressedOffsets()
static unsigned int log2(int val)
void setSQ(const std::string &sqMethod)
void setMaximumError(double maximumError)
std::vector< SimplexId > decompressedOffsets_
std::vector< double > & getDecompressedData()
void preconditionTriangulation(AbstractTriangulation *tri, const bool preproc=true)
int SimplexId
Identifier type for simplices of any dimension.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)