File: valid.c

package info (click to toggle)
libminc 2.4.07-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,288 kB
  • sloc: ansic: 57,268; cpp: 3,654; sh: 100; makefile: 23; ruby: 18
file content (126 lines) | stat: -rw-r--r-- 4,818 bytes parent folder | download | duplicates (9)
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
/** \file valid.c
 * \brief MINC 2.0 Valid Min/Max and Range Functions.
 * \author Bert Vincent
 *
 * These functions set and get the valid range of the datatype of a volume.
 * This range refers to the maximum values of the datatype as stored in the
 * file, not to the range of the "real" values.  For example, many scanners
 * store voxel data as unsigned, 12-bit integers.  Since there is no explicit
 * 12-bit data type in MINC, we may use these functions to set the valid range
 * in the image to 0..4095.
 ************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /*HAVE_CONFIG_H*/

#include <stdlib.h>
#include <hdf5.h>
#include "minc2.h"
#include "minc2_private.h"

/** This function gets the maximum valid value specific to the data
 *  type of the \a volume parameter.
 * \retval MI_ERROR on failure
 * \retval MI_NOERROR on success
 */
int
miget_volume_valid_max(mihandle_t volume, /**< MINC 2.0 volume handle */
                       double *valid_max) /**< the output value */
{
    if (volume == NULL || valid_max == NULL) {
        return MI_LOG_ERROR(MI2_MSG_GENERIC,"Trying to get valid range min with null volume or variable");      /* Invalid arguments */
    }
    *valid_max = volume->valid_max;
    return (MI_NOERROR);
}

/** This function sets the maximum valid value specific to the data
 *  type of the \a volume parameter.
 * \retval MI_ERROR on failure
 * \retval MI_NOERROR on success
 */
int miset_volume_valid_max(mihandle_t volume, /**< MINC 2.0 volume handle */
                       double valid_max) /**< the new maximum value  */
{
    if (volume == NULL) {
        return MI_LOG_ERROR(MI2_MSG_GENERIC,"Trying to set valid range max with null volume ");      /* Invalid arguments */
    }
    /* TODO?: Should we require valid max to have some specific relationship
     * to valid_min?
     */
    volume->valid_max = valid_max;
    misave_valid_range(volume);
    return (MI_NOERROR);
}

/** This function gets the minimum valid value specific to the data
 *  type of the \a volume parameter.
 * \retval MI_ERROR on failure
 * \retval MI_NOERROR on success
 */
int miget_volume_valid_min(mihandle_t volume, /**< MINC 2.0 volume handle */
                       double *valid_min) /**< the output value  */
{
    if (volume == NULL || valid_min == NULL) {
        return MI_LOG_ERROR(MI2_MSG_GENERIC,"Trying to get valid range min with null volume or variable");      /* Invalid arguments. */
    }
    *valid_min = volume->valid_min;
    return (MI_NOERROR);
}

/** This function sets the minimum valid value specific to the data
 *  type of the \a volume parameter.
 * \retval MI_ERROR on failure
 * \retval MI_NOERROR on success
 */
int miset_volume_valid_min(mihandle_t volume,  /**< MINC 2.0 volume handle */
                       double valid_min) /**< the new minimum value  */
{
    if (volume == NULL) {
        return MI_LOG_ERROR(MI2_MSG_GENERIC,"Trying to set valid range min with null volume ");       /* Invalid arguments */
    }
    volume->valid_min = valid_min;
    misave_valid_range(volume);
    return (MI_NOERROR);
}

/** This function gets the minimum and maximum valid value specific to the 
 * data type of the \a volume parameter.
 * \retval MI_ERROR on failure
 * \retval MI_NOERROR on success
 */
int miget_volume_valid_range(mihandle_t volume,  /**< MINC 2.0 volume handle */
                         double *valid_max, /**< the output maximum value */
                         double *valid_min) /**< the output minimum value */
{
    if (volume == NULL || valid_min == NULL || valid_max == NULL) {
        return MI_LOG_ERROR(MI2_MSG_GENERIC,"Trying to get valid range with null volume or null variables");
    }
    *valid_min = volume->valid_min;
    *valid_max = volume->valid_max;
    return (MI_NOERROR);
}

/** This function sets the minimum and maximum valid value specific to the 
 * data type of the \a volume parameter.
 * \retval MI_ERROR on failure
 * \retval MI_NOERROR on success
 */
int miset_volume_valid_range(mihandle_t volume, /**< MINC 2.0 volume handle */
                         double valid_max, /**< the new maximum value */
                         double valid_min) /**< the output minimum value */
{
    if (volume == NULL) {
        return MI_LOG_ERROR(MI2_MSG_GENERIC,"Trying to set valid range with null volume ");
    }
    /* TODO?: Again, should we require min<max, for example?  Or should we
     * just do the right thing and swap them?  What if valid_max is greater
     * than the maximum value that can be represented by the volume's type?
     */
    volume->valid_min = valid_min;
    volume->valid_max = valid_max;
    misave_valid_range(volume);
    return (MI_NOERROR);
}

/* kate: indent-mode cstyle; indent-width 2; replace-tabs on; */