Commit 274e4005 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Merge branch 'unsigned_short' into 'master'

Unsigned short

See merge request !58
parents 577ded75 5ebc61b3
Pipeline #16473 passed with stages
in 15 minutes and 41 seconds
......@@ -460,6 +460,8 @@ MarchingSquares<data_type>::march(const std::vector<data_type>& isovalues,
cpolygon.resize(top.size());
std::copy(top.begin(), top.end(), cpolygon.begin());
}
// remove the top element
pqueue.pop();
}
}
return contours;
......
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,2,2,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,2,2,3,3,2,2,2,0,0,0,0,0,0,0,0,0,0,0,
0,0,2,3,3,3,3,3,2,2,2,0,0,0,0,0,0,0,0,0,
0,0,2,3,3,3,3,3,3,3,2,2,2,0,0,0,0,0,0,0,
0,0,2,3,3,3,3,3,3,3,3,2,2,0,0,0,0,0,0,0,
0,0,2,2,2,2,2,2,2,2,2,2,2,0,0,0,2,2,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
......@@ -50,6 +50,16 @@ eafstream &eafstream::operator>>(short &value)
value = readShort();
return *this;
} // short
/**
* Operator overload for read unsigned short
* @param value unsigned short reference to be populated
* @return
*/
eafstream &eafstream::operator>>(unsigned short &value)
{
value = readUShort();
return *this;
} // short
/**
* Operator overload for read int
* @param value int reference to be populated
......@@ -210,6 +220,50 @@ void eafstream::writeShort(short var)
mBytesWritten += short_size;
}
/**
* \brief read a unsigned short integer from the offset in the file, accounting
* for endianness \return unsigned integer value .
*
*/
unsigned short eafstream::readUShort()
{
unsigned short var = 0;
this->read((char *)(&var), short_size);
if (this->bad() || this->eof())
{
std::stringstream ss;
ss << "Error, reading unsigned short from file at offset." << this->tellg();
std::cout << ss.str() << std::endl;
throw std::logic_error(ss.str());
}
if (mReverseBytes == true)
{
var = reverse_ushort_bytes(var);
}
// increment bytes read
mBytesRead += short_size;
return var;
} // readShort
void eafstream::writeUShort(unsigned short var)
{
if (mReverseBytes == true)
{
var = reverse_ushort_bytes(var);
}
this->write((char *)(&var), short_size);
if (this->bad() || this->eof())
{
std::stringstream ss;
ss << "Error, writing unsigned short to file at offset." << this->tellg();
std::cout << ss.str() << std::endl;
throw std::logic_error(ss.str());
}
mBytesWritten += short_size;
}
/**
* \brief read an integer from the offset in the file, accounting for
* endianness \return integer value or -1 on error.
......
......@@ -45,6 +45,12 @@ class RADIX_PUBLIC eafstream : public std::fstream
*/
short readShort();
void writeShort(short var);
/**
* \brief read a unsigned short integer from the file, accounting for
* endianness \return unsigned short value or -1 on error.
*/
unsigned short readUShort();
void writeUShort(unsigned short var);
/**
* \brief read an integer from the file, accounting for endianness
* \return integer value or -1 on error.
......@@ -132,6 +138,7 @@ class RADIX_PUBLIC eafstream : public std::fstream
int footer() const;
eafstream &operator>>(short &value);
eafstream &operator>>(unsigned short &value);
eafstream &operator>>(int &value);
eafstream &operator>>(float &value);
eafstream &operator>>(double &value);
......
......@@ -44,7 +44,18 @@ short reverse_short_bytes(short value)
short returnVal;
reverse_bytes((char *)&value, (void *)&returnVal, sizeof(short));
return returnVal;
} // reverse_int_bytes
} // reverse_short_bytes
/*!
* Reverses the bytes of an unsigned short
* */
unsigned short reverse_ushort_bytes(unsigned short value)
{
unsigned short returnVal;
reverse_bytes((char *)&value, (void *)&returnVal, sizeof(short));
return returnVal;
} // reverse_ushort_bytes
/*!
* Reverses the bytes of an integer
* */
......
......@@ -11,6 +11,7 @@ namespace radix
{
void RADIX_PUBLIC reverse_bytes(char *original, void *returnVal, int length);
short RADIX_PUBLIC reverse_short_bytes(short value);
unsigned short RADIX_PUBLIC reverse_ushort_bytes(unsigned short value);
int RADIX_PUBLIC reverse_int_bytes(int value);
void RADIX_PUBLIC reverse_array_int_bytes(int *array, int size);
void RADIX_PUBLIC reverse_array_float_bytes(float *array, int size);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment