mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 08:47:52 -06:00
TriangleSelector: 3MF loading and saving
This commit is contained in:
parent
7ddb64783b
commit
248fba82a4
4 changed files with 78 additions and 0 deletions
|
@ -1862,6 +1862,64 @@ void FacetsAnnotation::clear()
|
|||
|
||||
|
||||
|
||||
// Following function takes data from a triangle and encodes it as string
|
||||
// of hexadecimal numbers (one digit per triangle). Used for 3MF export,
|
||||
// changing it may break backwards compatibility !!!!!
|
||||
std::string FacetsAnnotation::get_triangle_as_string(int triangle_idx) const
|
||||
{
|
||||
std::string out;
|
||||
|
||||
auto triangle_it = m_data.find(triangle_idx);
|
||||
if (triangle_it != m_data.end()) {
|
||||
const std::vector<bool>& code = triangle_it->second;
|
||||
int offset = 0;
|
||||
while (offset < int(code.size())) {
|
||||
int next_code = 0;
|
||||
for (int i=3; i>=0; --i) {
|
||||
next_code = next_code << 1;
|
||||
next_code |= int(code[offset + i]);
|
||||
}
|
||||
offset += 4;
|
||||
|
||||
assert(next_code >=0 && next_code <= 15);
|
||||
char digit = next_code < 10 ? next_code + '0' : (next_code-10)+'A';
|
||||
out.insert(out.begin(), digit);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Recover triangle splitting & state from string of hexadecimal values previously
|
||||
// generated by get_triangle_as_string. Used to load from 3MF.
|
||||
void FacetsAnnotation::set_triangle_from_string(int triangle_id, const std::string& str)
|
||||
{
|
||||
assert(! str.empty());
|
||||
m_data[triangle_id] = std::vector<bool>(); // zero current state or create new
|
||||
std::vector<bool>& code = m_data[triangle_id];
|
||||
|
||||
for (auto it = str.crbegin(); it != str.crend(); ++it) {
|
||||
const char ch = *it;
|
||||
int dec = 0;
|
||||
if (ch >= '0' && ch<='9')
|
||||
dec = int(ch - '0');
|
||||
else if (ch >='A' && ch <= 'F')
|
||||
dec = 10 + int(ch - 'A');
|
||||
else
|
||||
assert(false);
|
||||
|
||||
// Convert to binary and append into code.
|
||||
for (int i=0; i<4; ++i) {
|
||||
code.insert(code.end(), bool(dec & (1 << i)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Test whether the two models contain the same number of ModelObjects with the same set of IDs
|
||||
// ordered in the same order. In that case it is not necessary to kill the background processing.
|
||||
bool model_object_list_equal(const Model &model_old, const Model &model_new)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue