| 90 | } |
| 91 | |
| 92 | CachedFileRcPtr LocalFileFormat::read(std::istream & istream, |
| 93 | const std::string & fileName, |
| 94 | Interpolation interp) const |
| 95 | { |
| 96 | // this shouldn't happen |
| 97 | if(!istream) |
| 98 | { |
| 99 | throw Exception ("File stream empty when trying to read .vf LUT"); |
| 100 | } |
| 101 | |
| 102 | // Validate the file type |
| 103 | std::string line; |
| 104 | int lineNumber = 1; |
| 105 | if(!nextline(istream, line) || |
| 106 | !StringUtils::StartsWith(StringUtils::Lower(line), "#inventor")) |
| 107 | { |
| 108 | ThrowErrorMessage("Expecting '#Inventor V2.1 ascii'.", |
| 109 | fileName, lineNumber, line); |
| 110 | } |
| 111 | |
| 112 | // Parse the file |
| 113 | std::vector<float> raw3d; |
| 114 | int size3d[] = { 0, 0, 0 }; |
| 115 | std::vector<float> global_transform; |
| 116 | |
| 117 | { |
| 118 | StringUtils::StringVec parts; |
| 119 | std::vector<float> tmpfloats; |
| 120 | |
| 121 | bool in3d = false; |
| 122 | |
| 123 | while(nextline(istream, line)) |
| 124 | { |
| 125 | ++lineNumber; |
| 126 | |
| 127 | // Strip, lowercase, and split the line |
| 128 | parts = StringUtils::SplitByWhiteSpaces(StringUtils::Lower(StringUtils::Trim(line))); |
| 129 | |
| 130 | if(parts.empty()) continue; |
| 131 | |
| 132 | if(StringUtils::StartsWith(parts[0],'#')) continue; |
| 133 | |
| 134 | if(!in3d) |
| 135 | { |
| 136 | if(parts[0] == "grid_size") |
| 137 | { |
| 138 | if(parts.size() != 4 || |
| 139 | !StringToInt( &size3d[0], parts[1].c_str()) || |
| 140 | !StringToInt( &size3d[1], parts[2].c_str()) || |
| 141 | !StringToInt( &size3d[2], parts[3].c_str())) |
| 142 | { |
| 143 | ThrowErrorMessage( |
| 144 | "Malformed grid_size tag.", |
| 145 | fileName, lineNumber, line); |
| 146 | } |
| 147 | |
| 148 | // TODO: Support nununiformly sized LUTs. |
| 149 | if (size3d[0] != size3d[1] || |
no test coverage detected