|
| 1 | +/* |
| 2 | + * ARMarkerNFT.c |
| 3 | + * ARToolKit5 |
| 4 | + * |
| 5 | + * Disclaimer: IMPORTANT: This Daqri software is supplied to you by Daqri |
| 6 | + * LLC ("Daqri") in consideration of your agreement to the following |
| 7 | + * terms, and your use, installation, modification or redistribution of |
| 8 | + * this Daqri software constitutes acceptance of these terms. If you do |
| 9 | + * not agree with these terms, please do not use, install, modify or |
| 10 | + * redistribute this Daqri software. |
| 11 | + * |
| 12 | + * In consideration of your agreement to abide by the following terms, and |
| 13 | + * subject to these terms, Daqri grants you a personal, non-exclusive |
| 14 | + * license, under Daqri's copyrights in this original Daqri software (the |
| 15 | + * "Daqri Software"), to use, reproduce, modify and redistribute the Daqri |
| 16 | + * Software, with or without modifications, in source and/or binary forms; |
| 17 | + * provided that if you redistribute the Daqri Software in its entirety and |
| 18 | + * without modifications, you must retain this notice and the following |
| 19 | + * text and disclaimers in all such redistributions of the Daqri Software. |
| 20 | + * Neither the name, trademarks, service marks or logos of Daqri LLC may |
| 21 | + * be used to endorse or promote products derived from the Daqri Software |
| 22 | + * without specific prior written permission from Daqri. Except as |
| 23 | + * expressly stated in this notice, no other rights or licenses, express or |
| 24 | + * implied, are granted by Daqri herein, including but not limited to any |
| 25 | + * patent rights that may be infringed by your derivative works or by other |
| 26 | + * works in which the Daqri Software may be incorporated. |
| 27 | + * |
| 28 | + * The Daqri Software is provided by Daqri on an "AS IS" basis. DAQRI |
| 29 | + * MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION |
| 30 | + * THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS |
| 31 | + * FOR A PARTICULAR PURPOSE, REGARDING THE DAQRI SOFTWARE OR ITS USE AND |
| 32 | + * OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
| 33 | + * |
| 34 | + * IN NO EVENT SHALL DAQRI BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL |
| 35 | + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 36 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 37 | + * INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, |
| 38 | + * MODIFICATION AND/OR DISTRIBUTION OF THE DAQRI SOFTWARE, HOWEVER CAUSED |
| 39 | + * AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), |
| 40 | + * STRICT LIABILITY OR OTHERWISE, EVEN IF DAQRI HAS BEEN ADVISED OF THE |
| 41 | + * POSSIBILITY OF SUCH DAMAGE. |
| 42 | + * |
| 43 | + * Copyright 2015 Daqri LLC. All Rights Reserved. |
| 44 | + * Copyright 2013-2015 ARToolworks, Inc. All Rights Reserved. |
| 45 | + * |
| 46 | + * Author(s): Philip Lamb. |
| 47 | + * |
| 48 | + */ |
| 49 | + |
| 50 | +#include "ARMarkerNFT.h" |
| 51 | + |
| 52 | +#include <stdio.h> |
| 53 | +#include <string.h> |
| 54 | +#ifdef _WIN32 |
| 55 | +# include <windows.h> |
| 56 | +# define MAXPATHLEN MAX_PATH |
| 57 | +#else |
| 58 | +# include <sys/param.h> // MAXPATHLEN |
| 59 | +#endif |
| 60 | + |
| 61 | + |
| 62 | +const ARPose ARPoseUnity = {{1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}; |
| 63 | + |
| 64 | +static char *get_buff(char *buf, int n, FILE *fp, int skipblanks) |
| 65 | +{ |
| 66 | + char *ret; |
| 67 | + size_t l; |
| 68 | + |
| 69 | + do { |
| 70 | + ret = fgets(buf, n, fp); |
| 71 | + if (ret == NULL) return (NULL); // EOF or error. |
| 72 | + |
| 73 | + // Remove NLs and CRs from end of string. |
| 74 | + l = strlen(buf); |
| 75 | + while (l > 0) { |
| 76 | + if (buf[l - 1] != '\n' && buf[l - 1] != '\r') break; |
| 77 | + l--; |
| 78 | + buf[l] = '\0'; |
| 79 | + } |
| 80 | + } while (buf[0] == '#' || (skipblanks && buf[0] == '\0')); // Reject comments and blank lines. |
| 81 | + |
| 82 | + return (ret); |
| 83 | +} |
| 84 | + |
| 85 | +void newMarkers(const char *markersConfigDataFilePathC, ARMarkerNFT **markersNFT_out, int *markersNFTCount_out) |
| 86 | +{ |
| 87 | + FILE *fp; |
| 88 | + char buf[MAXPATHLEN], buf1[MAXPATHLEN]; |
| 89 | + int tempI; |
| 90 | + ARMarkerNFT *markersNFT; |
| 91 | + int markersNFTCount; |
| 92 | + ARdouble tempF; |
| 93 | + int i; |
| 94 | + char markersConfigDataDirC[MAXPATHLEN]; |
| 95 | + size_t markersConfigDataDirCLen; |
| 96 | + |
| 97 | + if (!markersConfigDataFilePathC || markersConfigDataFilePathC[0] == '\0' || !markersNFT_out || !markersNFTCount_out) return; |
| 98 | + |
| 99 | + // Load the marker data file. |
| 100 | + ARLOGd("Opening marker config. data file from path '%s'.\n", markersConfigDataFilePathC); |
| 101 | + arUtilGetDirectoryNameFromPath(markersConfigDataDirC, markersConfigDataFilePathC, MAXPATHLEN, 1); // 1 = add '/' at end. |
| 102 | + markersConfigDataDirCLen = strlen(markersConfigDataDirC); |
| 103 | + if ((fp = fopen(markersConfigDataFilePathC, "r")) == NULL) { |
| 104 | + ARLOGe("Error: unable to locate marker config data file '%s'.\n", markersConfigDataFilePathC); |
| 105 | + return; |
| 106 | + } |
| 107 | + |
| 108 | + // First line is number of markers to read. |
| 109 | + get_buff(buf, MAXPATHLEN, fp, 1); |
| 110 | + if (sscanf(buf, "%d", &tempI) != 1 ) { |
| 111 | + ARLOGe("Error in marker configuration data file; expected marker count.\n"); |
| 112 | + fclose(fp); |
| 113 | + return; |
| 114 | + } |
| 115 | + |
| 116 | + arMallocClear(markersNFT, ARMarkerNFT, tempI); |
| 117 | + markersNFTCount = tempI; |
| 118 | + |
| 119 | + ARLOGd("Reading %d marker configuration(s).\n", markersNFTCount); |
| 120 | + |
| 121 | + for (i = 0; i < markersNFTCount; i++) { |
| 122 | + |
| 123 | + // Read marker name. |
| 124 | + if (!get_buff(buf, MAXPATHLEN, fp, 1)) { |
| 125 | + ARLOGe("Error in marker configuration data file; expected marker name.\n"); |
| 126 | + break; |
| 127 | + } |
| 128 | + |
| 129 | + // Read marker type. |
| 130 | + if (!get_buff(buf1, MAXPATHLEN, fp, 1)) { |
| 131 | + ARLOGe("Error in marker configuration data file; expected marker type.\n"); |
| 132 | + break; |
| 133 | + } |
| 134 | + |
| 135 | + // Interpret marker type, and read more data. |
| 136 | + if (strcmp(buf1, "SINGLE") == 0) { |
| 137 | + ARLOGe("Error in marker configuration data file; SINGLE markers not supported in this build.\n"); |
| 138 | + } else if (strcmp(buf1, "MULTI") == 0) { |
| 139 | + ARLOGe("Error in marker configuration data file; MULTI markers not supported in this build.\n"); |
| 140 | + } else if (strcmp(buf1, "NFT") == 0) { |
| 141 | + markersNFT[i].valid = markersNFT[i].validPrev = FALSE; |
| 142 | + arMalloc(markersNFT[i].datasetPathname, char, markersConfigDataDirCLen + strlen(buf) + 1); |
| 143 | + strcpy(markersNFT[i].datasetPathname, markersConfigDataDirC); |
| 144 | + strcpy(markersNFT[i].datasetPathname + markersConfigDataDirCLen, buf); |
| 145 | + markersNFT[i].pageNo = -1; |
| 146 | + } else { |
| 147 | + ARLOGe("Error in marker configuration data file; unsupported marker type %s.\n", buf1); |
| 148 | + } |
| 149 | + |
| 150 | + // Look for optional tokens. A blank line marks end of options. |
| 151 | + while (get_buff(buf, MAXPATHLEN, fp, 0) && (buf[0] != '\0')) { |
| 152 | + if (strncmp(buf, "FILTER", 6) == 0) { |
| 153 | + markersNFT[i].filterCutoffFrequency = AR_FILTER_TRANS_MAT_CUTOFF_FREQ_DEFAULT; |
| 154 | + markersNFT[i].filterSampleRate = AR_FILTER_TRANS_MAT_SAMPLE_RATE_DEFAULT; |
| 155 | + if (strlen(buf) != 6) { |
| 156 | + if (sscanf(&buf[6], |
| 157 | +#ifdef ARDOUBLE_IS_FLOAT |
| 158 | + "%f" |
| 159 | +#else |
| 160 | + "%lf" |
| 161 | +#endif |
| 162 | + , &tempF) == 1) markersNFT[i].filterCutoffFrequency = tempF; |
| 163 | + } |
| 164 | + markersNFT[i].ftmi = arFilterTransMatInit(markersNFT[i].filterSampleRate, markersNFT[i].filterCutoffFrequency); |
| 165 | + } |
| 166 | + // Unknown tokens are ignored. |
| 167 | + } |
| 168 | + } |
| 169 | + fclose(fp); |
| 170 | + |
| 171 | + // If not all markers were read, an error occurred. |
| 172 | + if (i < markersNFTCount) { |
| 173 | + |
| 174 | + // Clean up. |
| 175 | + for (; i >= 0; i--) { |
| 176 | + if (markersNFT[i].datasetPathname) free(markersNFT[i].datasetPathname); |
| 177 | + if (markersNFT[i].ftmi) arFilterTransMatFinal(markersNFT[i].ftmi); |
| 178 | + } |
| 179 | + free(markersNFT); |
| 180 | + |
| 181 | + *markersNFTCount_out = 0; |
| 182 | + *markersNFT_out = NULL; |
| 183 | + return; |
| 184 | + } |
| 185 | + |
| 186 | + *markersNFTCount_out = markersNFTCount; |
| 187 | + *markersNFT_out = markersNFT; |
| 188 | +} |
| 189 | + |
| 190 | +void deleteMarkers(ARMarkerNFT **markersNFT_p, int *markersNFTCount_p) |
| 191 | +{ |
| 192 | + int i; |
| 193 | + |
| 194 | + if (!markersNFT_p || !*markersNFT_p || !*markersNFTCount_p || *markersNFTCount_p < 1) return; |
| 195 | + |
| 196 | + for (i = 0; i < *markersNFTCount_p; i++) { |
| 197 | + if ((*markersNFT_p)[i].datasetPathname) { |
| 198 | + free((*markersNFT_p)[i].datasetPathname); |
| 199 | + (*markersNFT_p)[i].datasetPathname = NULL; |
| 200 | + } |
| 201 | + if ((*markersNFT_p)[i].ftmi) { |
| 202 | + arFilterTransMatFinal((*markersNFT_p)[i].ftmi); |
| 203 | + (*markersNFT_p)[i].ftmi = NULL; |
| 204 | + } |
| 205 | + } |
| 206 | + free(*markersNFT_p); |
| 207 | + *markersNFT_p = NULL; |
| 208 | + *markersNFTCount_p = 0; |
| 209 | +} |
0 commit comments