Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/lib/include/diderot/nrrd-inst.hxx
ViewVC logotype

Diff of /branches/vis15/src/lib/include/diderot/nrrd-inst.hxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4027, Wed Jun 22 17:38:35 2016 UTC revision 4028, Wed Jun 22 21:15:36 2016 UTC
# Line 197  Line 197 
197    
198          } // copy_nrrd_data_real          } // copy_nrrd_data_real
199    
200            template <typename T>
201            dynseq<T> load_dynseq_from_nrrd (const Nrrd *nin, bool &sts)
202            {
203                uint32_t nDims = dynseq<T>::traits::ndims;
204                const uint32_t *dims = dynseq<T>::traits::dims;
205                uint32_t nValuesPerElem = wrld->check_nrrd (nin, nDims, dims);
206                size_t elemSz = sizeof(dynseq<T>::traits::base_type) * nValuesPerElem;
207    
208                if (nValuesPerElem == 0) {
209                    return dynseq<T>();
210                }
211    
212    //          if (nrrd_type_info[nin->type].isFloat) {
213    //              wrld->error ("expected integer element type for int sequence, but found %d\n",
214    //                  nin->type);
215    //              return true;
216    //          }
217    
218              // get the number of elements
219                size_t nElems = nin->axis[0].size;
220    
221              // allocate the result sequence object
222                dynseq<T> result(nElems);
223    
224              // initialize the sequence from the nrrd
225                dynseq<T>::traits::base_type *dst =
226                    reinterpret_cast<dynseq<T>::traits::base_type *>(result.data());
227    
228                if (nrrd_type_info[nin->type].sizeb != sizeof(dynseq<T>::traits::base_type)) {
229                  // this is the slow path; we have to convert values as they are copied from the nrrd
230                    load_fn_ptr loadFn = dynseq<T>::traits::get_load_fn (nin->type);
231                    char *src = (char *)nin->data;
232                    size_t srcElemSz = nrrd_type_info[nin->type].sizeb;
233                    for (size_t i = 0;  i < nElems * nValuesPerElem;  i++) {
234                        *dst++ = loadFn(src);
235                        src += srcElemSz;
236                    }
237                }
238                else {
239                  // this is the fast path, where we can just do a bulk memcpy
240                    memcpy (dst, nin->data, nElems * elemSz);
241                }
242    
243                return result;
244    
245            }
246    
247      } // namespace __details      } // namespace __details
248    
249  } // namespace diderot  } // namespace diderot

Legend:
Removed from v.4027  
changed lines
  Added in v.4028

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0