Datasets:

Modalities:
Image
Text
Formats:
text
Size:
< 1K
Libraries:
Datasets
License:
File size: 9,633 Bytes
5b89cb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// This file is part of libigl, a simple c++ geometry processing library.
// 
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
// 
// This Source Code Form is subject to the terms of the Mozilla Public License 
// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
// obtain one at http://mozilla.org/MPL/2.0/.
#ifndef IGL_XML_REANTTWEAKBAR_XML_SERIALIZATION_H
#define IGL_XML_REANTTWEAKBAR_XML_SERIALIZATION_H
#include "../igl_inline.h"
#include "serialize_xml.h"

#undef IGL_HEADER_ONLY
#include "../anttweakbar/ReAntTweakBar.h"

// Forward declarations
namespace igl
{
  namespace anttweakbar
  {
    class ReTwBar;
  }
};
namespace tinyxml2
{
  class XMLDocument;
};

namespace igl
{
  namespace xml
  {
  
//  namespace
//  {
  
//    IGL_INLINE bool save_ReAntTweakBar(::igl::anttweakbar::ReTwBar* bar, const char* file_name);
//    IGL_INLINE bool save_ReAntTweakBar(::igl::anttweakbar::ReTwBar* bar, tinyxml2::XMLDocument* doc);
//    IGL_INLINE bool load_ReAntTweakBar(::igl::anttweakbar::ReTwBar* bar, const char *file_name);
//    IGL_INLINE bool load_ReAntTweakBar(::igl::anttweakbar::ReTwBar* bar, tinyxml2::XMLDocument* doc);
    
    
    IGL_INLINE bool save_ReAntTweakBar(::igl::anttweakbar::ReTwBar* bar, const char* file_name)
    {
      const char * name_chars = TwGetBarName(bar->bar);
      std::string name = std::string(name_chars) + "_AntTweakBar";
      
      const std::vector< ::igl::anttweakbar::ReTwRWItem>& rw_items = bar->get_rw_items();
      for(std::vector< ::igl::anttweakbar::ReTwRWItem>::const_iterator it = rw_items.begin(); it != rw_items.end(); it++)
      {
        std::string val = bar->get_value_as_string(it->var,it->type);
        //::igl::XMLSerializer::SaveObject(val,it->name,name,file_name,false);
        ::igl::serialize_xml(val,it->name,file_name,false,false);
      }
      
      char var[REANTTWEAKBAR_MAX_CB_VAR_SIZE];
      // Print all CB variables
      const std::vector< ::igl::anttweakbar::ReTwCBItem>& cb_items = bar->get_cb_items();
      for(std::vector< ::igl::anttweakbar::ReTwCBItem>::const_iterator it = cb_items.begin(); it != cb_items.end(); it++)
      {
        TwType type = it->type;
        //TwSetVarCallback setCallback = it->setCallback;
        TwGetVarCallback getCallback = it->getCallback;
        void * clientData = it->clientData;
        // I'm not sure how to do what I want to do. getCallback needs to be sure
        // that it can write to var. So var needs to point to a valid and big
        // enough chunk of memory
        getCallback(var,clientData);
        
        std::string val = bar->get_value_as_string(var,type);
        //::igl::XMLSerializer::SaveObject(val,it->name,name,file_name,false);
        ::igl::serialize_xml(val,it->name,file_name,false,false);
      }
      
      return true;
    }
    
    /*IGL_INLINE bool save_ReAntTweakBar(::igl::anttweakbar::ReTwBar* bar, tinyxml2::XMLDocument* doc)
    {
      std::vector<char**> buffer;
      
      const char * name_chars = TwGetBarName(bar->bar);
      std::string name = std::string(name_chars) + "_AntTweakBar";
      ::igl::XMLSerializer* s = new ::igl::XMLSerializer(name);
      
      const std::vector< ::igl::anttweakbar::ReTwRWItem>& rw_items = bar->get_rw_items();
      for(std::vector< ::igl::anttweakbar::ReTwRWItem>::const_iterator it = rw_items.begin(); it != rw_items.end(); it++)
      {
        std::string val = bar->get_value_as_string(it->var,it->type);
        char** cval = new char*; // create char* on heap
        *cval = new char[val.size()+1];
        buffer.push_back(cval);
        strcpy(*cval,val.c_str());
        s->Add(*cval,it->name);
      }
      
      char var[REANTTWEAKBAR_MAX_CB_VAR_SIZE];
      // Print all CB variables
      const std::vector< ::igl::anttweakbar::ReTwCBItem>& cb_items = bar->get_cb_items();
      for(std::vector< ::igl::anttweakbar::ReTwCBItem>::const_iterator it = cb_items.begin(); it != cb_items.end(); it++)
      {
        TwType type = it->type;
        //TwSetVarCallback setCallback = it->setCallback;
        TwGetVarCallback getCallback = it->getCallback;
        void * clientData = it->clientData;
        // I'm not sure how to do what I want to do. getCallback needs to be sure
        // that it can write to var. So var needs to point to a valid and big
        // enough chunk of memory
        getCallback(var,clientData);
        
        std::string val = bar->get_value_as_string(var,type);
        char** cval = new char*; // create char* on heap
        *cval = new char[val.size()+1];
        buffer.push_back(cval);
        strcpy(*cval,val.c_str());
        s->Add(*cval,it->name);
      }
      
      s->SaveToXMLDoc(name,doc);
      
      // delete pointer buffers
      for(unsigned int i=0;i<buffer.size();i++)
      {
        delete[] *buffer[i];
        delete buffer[i];
      }
      
      delete s;
      
      return true;
    }*/
    
    IGL_INLINE bool load_ReAntTweakBar(::igl::anttweakbar::ReTwBar* bar, const char *file_name)
    {
      char type_str[REANTTWEAKBAR_MAX_WORD];
      char value_str[REANTTWEAKBAR_MAX_WORD];
      TwType type;
      
      const char * name_chars = TwGetBarName(bar->bar);
      std::string name = std::string(name_chars) + "_AntTweakBar";
      
      const std::vector< ::igl::anttweakbar::ReTwRWItem>& rw_items = bar->get_rw_items();
      for(std::vector< ::igl::anttweakbar::ReTwRWItem>::const_iterator it = rw_items.begin(); it != rw_items.end(); it++)
      {
        char* val;
        //::igl::XMLSerializer::LoadObject(val,it->name,name,file_name);
        ::igl::deserialize_xml(val,it->name,file_name);
        sscanf(val,"%s %[^\n]",type_str,value_str);
        
        if(!bar->type_from_string(type_str,type))
        {
          printf("ERROR: %s type not found... Skipping...\n",type_str);
          continue;
        }
        
        bar->set_value_from_string(it->name.c_str(),type,value_str);
        delete[] val;
      }
      
      const std::vector< ::igl::anttweakbar::ReTwCBItem>& cb_items = bar->get_cb_items();
      for(std::vector< ::igl::anttweakbar::ReTwCBItem>::const_iterator it = cb_items.begin(); it != cb_items.end(); it++)
      {
        char* val;
        //::igl::XMLSerializer::LoadObject(val,it->name,name,file_name);
        ::igl::deserialize_xml(val,it->name,file_name);
        sscanf(val,"%s %[^\n]",type_str,value_str);
        
        if(!bar->type_from_string(type_str,type))
        {
          printf("ERROR: %s type not found... Skipping...\n",type_str);
          continue;
        }
        
        bar->set_value_from_string(it->name.c_str(),type,value_str);
        delete[] val;
      }
      
      return true;
    }
    
    /*IGL_INLINE bool load_ReAntTweakBar(::igl::anttweakbar::ReTwBar* bar, tinyxml2::XMLDocument* doc)
    {
      std::map<std::string,char*> variables;
      std::map<std::string,char*> cbVariables;
      
      const char * name_chars = TwGetBarName(bar->bar);
      std::string name = std::string(name_chars) + "_AntTweakBar";
      ::igl::XMLSerializer* s = new ::igl::XMLSerializer(name);
      
      std::map<std::string,char*>::iterator iter;
      const std::vector< ::igl::anttweakbar::ReTwRWItem>& rw_items = bar->get_rw_items();
      for(std::vector< ::igl::anttweakbar::ReTwRWItem>::const_iterator it = rw_items.begin(); it != rw_items.end(); it++)
      {
        variables[it->name] = NULL;
        iter = variables.find(it->name);
        s->Add(iter->second,iter->first);
      }
      
      // Add all CB variables
      const std::vector< ::igl::anttweakbar::ReTwCBItem>& cb_items = bar->get_cb_items();
      for(std::vector< ::igl::anttweakbar::ReTwCBItem>::const_iterator it = cb_items.begin(); it != cb_items.end(); it++)
      {
        cbVariables[it->name] = NULL;
        iter = cbVariables.find(it->name);
        s->Add(iter->second,iter->first);
      }
      
      s->LoadFromXMLDoc(doc);
      
      // Set loaded values
      char type_str[REANTTWEAKBAR_MAX_WORD];
      char value_str[REANTTWEAKBAR_MAX_WORD];
      TwType type;
      
      for(iter = variables.begin(); iter != variables.end(); iter++)
      {
        if(iter->second == NULL)
        {
          printf("ERROR: '%s' entry not found... Skipping...\n",iter->first.c_str());
          continue;
        }
        
        sscanf(iter->second,"%s %[^\n]",type_str,value_str);
        
        if(!bar->type_from_string(type_str,type))
        {
          printf("ERROR: Type '%s' of '%s' not found... Skipping...\n",type_str,iter->first.c_str());
          continue;
        }
        
        bar->set_value_from_string(iter->first.c_str(),type,value_str);
      }
      
      for(iter = cbVariables.begin(); iter != cbVariables.end(); iter++)
      {
        if(iter->second == NULL)
        {
          printf("ERROR: '%s' entry not found... Skipping...\n",iter->first.c_str());
          continue;
        }

        sscanf(iter->second,"%s %[^\n]",type_str,value_str);
        
        if(!bar->type_from_string(type_str,type))
        {
          printf("ERROR: Type '%s' of '%s' not found... Skipping...\n",type_str,iter->first.c_str());
          continue;
        }
        
        bar->set_value_from_string(iter->first.c_str(),type,value_str);
      }
      
      // delete buffers
      for(iter = variables.begin(); iter != variables.end(); iter++)
        delete[] iter->second;
      
      for(iter = cbVariables.begin(); iter != cbVariables.end(); iter++)
        delete[] iter->second;
      
      delete s;
      
      return true;
    }*/
    
//  }
  }
}

#endif