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

SCM Repository

[diderot] Annotation of /branches/vis15/src/lib/common/world.cxx
ViewVC logotype

Annotation of /branches/vis15/src/lib/common/world.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3987 - (view) (download) (as text)

1 : jhr 3987 /*! \file world.cxx
2 : jhr 3824 *
3 :     * \author John Reppy
4 :     */
5 :    
6 :     /*
7 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
8 :     *
9 :     * COPYRIGHT (c) 2016 The University of Chicago
10 :     * All rights reserved.
11 :     */
12 :    
13 :     #include <cstdlib>
14 : jhr 3895 #include "diderot/world.hxx"
15 : jhr 3987 #include "diderot/nrrd-inst.hxx"
16 : jhr 3824
17 : jhr 3895 namespace diderot {
18 : jhr 3824
19 : jhr 3987 //! Check that a nrrd has the expected structure for loading into a dynamic sequence
20 :     //! \param nin the nrrd to check
21 :     //! \param nDims the number of dimensions in the sequence elements
22 :     //! \param dims the array of sequence element dimensions
23 :     //! \return the number of values per element, or zero on error
24 :     uint32_t world_base::check_nrrd (Nrrd *nin, uint32_t nDims, uint32_t *dims)
25 :     {
26 :     // compute the expected number of values per sequence element
27 :     uint32_t nValuesPerElem = 1;
28 :     for (uint32_t i = 0; i < nDims; i++) {
29 :     nValuesPerElem *= dims[i];
30 :     }
31 : jhr 3824
32 : jhr 3987 // check the structure of the nrrd file
33 :     if (nin->spaceDim != 0) {
34 :     this->error ("unexpected number of axes in nrrd; expected 0, found %d\n",
35 :     nin->spaceDim);
36 :     return 0;
37 :     }
38 :     if (nin->dim - 1 != nDims) {
39 :     this->error ("unexpected nrrd dimension; expected %d, found %d\n",
40 :     nDims, nin->dim-1);
41 :     return 0;
42 :     }
43 :     for (unsigned int i = 0; i < nDims; i++) {
44 :     if (dims[i] != nin->axis[i].size) {
45 :     this->error ("nrrd axis %d does not match expected dimension: %d != %d\n",
46 :     i+1, dims[i], nin->axis[i].size);
47 :     return 0;
48 :     }
49 :     }
50 :     if (__details::nrrd_type_info[nin->type].sizeb == 0) {
51 :     this->error ("bogus element type %d in nrrd\n", nin->type);
52 :     return 0;
53 :     }
54 :    
55 :     return nValuesPerElem;
56 : jhr 3824 }
57 :    
58 : jhr 3987 Nrrd *world_base::load_nrrd_file (std::string const &filename)
59 :     {
60 :     /* create a nrrd; at this point it is just an empty container */
61 :     Nrrd *nin = nrrdNew();
62 : jhr 3824
63 : jhr 3987 /* read in the nrrd from the file */
64 :     if (nrrdLoad(nin, filename.c_str(), nullptr) != 0) {
65 :     char *msg = biffGetDone(NRRD);
66 :     biffMsgAdd (this->_errors, msg);
67 :     std::free (msg);
68 :     return nullptr;
69 :     }
70 : jhr 3824
71 : jhr 3987 return nin;
72 : jhr 3825
73 : jhr 3987 }
74 : jhr 3825
75 : jhr 3987 void world_base::error (const char *fmt, ...)
76 :     {
77 :     char buf[1024];
78 :     va_list ap;
79 : jhr 3825
80 : jhr 3987 // NOTE: if there was a biffMsg function that worked with va_lists, then we
81 :     // could avoid the buffer
82 :     va_start (ap, fmt);
83 :     vsnprintf (buf, sizeof(buf), fmt, ap);
84 :     va_end (ap);
85 : jhr 3825
86 : jhr 3987 biffMsgAdd (this->_errors, buf);
87 :     }
88 :    
89 : jhr 3824 } // namespace Diderot

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