Skip to content

Commit fb6b1e6

Browse files
author
Daniel Wickeroth
committed
no hardcoded filenames
1 parent e6492a0 commit fb6b1e6

2 files changed

Lines changed: 53 additions & 15 deletions

File tree

src/OpenCOVER/plugins/ukoeln/colorAnim/ColorAnimPlugin.cpp

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ bool ColorAnimPlugin::init()
137137
});
138138

139139
// Load brain models
140-
std::string brainPath = coCoviseConfig::getEntry("value", "COVER.Plugin.ColorAnim.ModelPath", "");
141-
if (brainPath.empty())
140+
std::string firstFilePath = coCoviseConfig::getEntry("value", "COVER.Plugin.ColorAnim.FirstModel", "");
141+
if (firstFilePath.empty())
142142
{
143-
fprintf(stderr, "ColorAnimPlugin: No model path configured. Please set COVER.Plugin.ColorAnim.ModelPath in config\n");
144-
fprintf(stderr, "ColorAnimPlugin: Trying to load from current directory ./brain_*.obj\n");
145-
brainPath = "./brain";
143+
fprintf(stderr, "ColorAnimPlugin: No first model path configured. Please set COVER.Plugin.ColorAnim.FirstModel in config\n");
144+
fprintf(stderr, "ColorAnimPlugin: Example: /path/to/data/highres_cortex_001.ply\n");
145+
return false;
146146
}
147147

148-
if (!loadBrainModels(brainPath))
148+
if (!loadBrainModels(firstFilePath))
149149
{
150150
fprintf(stderr, "ColorAnimPlugin: Failed to load brain models\n");
151151
return false;
@@ -171,19 +171,56 @@ bool ColorAnimPlugin::init()
171171
return true;
172172
}
173173

174-
bool ColorAnimPlugin::loadBrainModels(const std::string &basePath)
174+
bool ColorAnimPlugin::loadBrainModels(const std::string &firstFilePath)
175175
{
176-
fprintf(stderr, "ColorAnimPlugin: Loading brain models from %s\n", basePath.c_str());
176+
fprintf(stderr, "ColorAnimPlugin: Loading brain models starting from %s\n", firstFilePath.c_str());
177177

178-
// Try to load the first model to get geometry
179-
std::ostringstream firstPath;
180-
firstPath << basePath << "highres_cortex_001.ply";
178+
// Parse the first file path to extract directory, base name, number, and extension
179+
size_t lastSlash = firstFilePath.find_last_of("/\\");
180+
std::string directory = (lastSlash != std::string::npos) ? firstFilePath.substr(0, lastSlash + 1) : "";
181+
std::string filename = (lastSlash != std::string::npos) ? firstFilePath.substr(lastSlash + 1) : firstFilePath;
182+
183+
// Find the last sequence of digits in the filename
184+
size_t digitEnd = filename.length();
185+
size_t digitStart = digitEnd;
181186

182-
osg::ref_ptr<osg::Node> firstModel = osgDB::readNodeFile(firstPath.str());
187+
// Find extension (last dot)
188+
size_t extPos = filename.find_last_of('.');
189+
std::string extension = (extPos != std::string::npos) ? filename.substr(extPos) : "";
190+
191+
// Look for digits before the extension
192+
if (extPos != std::string::npos)
193+
{
194+
digitEnd = extPos;
195+
digitStart = extPos;
196+
197+
// Find the start of the digit sequence
198+
while (digitStart > 0 && isdigit(filename[digitStart - 1]))
199+
{
200+
digitStart--;
201+
}
202+
}
203+
204+
if (digitStart >= digitEnd)
205+
{
206+
fprintf(stderr, "ColorAnimPlugin: Could not find number pattern in filename: %s\n", filename.c_str());
207+
return false;
208+
}
209+
210+
std::string baseFileName = filename.substr(0, digitStart);
211+
std::string numberStr = filename.substr(digitStart, digitEnd - digitStart);
212+
int startNumber = std::atoi(numberStr.c_str());
213+
int numberWidth = numberStr.length(); // Zero-padding width
214+
215+
fprintf(stderr, "ColorAnimPlugin: Parsed pattern - base: '%s', start: %d, width: %d, ext: '%s'\n",
216+
baseFileName.c_str(), startNumber, numberWidth, extension.c_str());
217+
218+
// Try to load the first model to get geometry
219+
osg::ref_ptr<osg::Node> firstModel = osgDB::readNodeFile(firstFilePath);
183220

184221
if (!firstModel.valid())
185222
{
186-
fprintf(stderr, "ColorAnimPlugin: Could not load first model: %s\n", firstPath.str().c_str());
223+
fprintf(stderr, "ColorAnimPlugin: Could not load first model: %s\n", firstFilePath.c_str());
187224
return false;
188225
}
189226

@@ -231,7 +268,8 @@ bool ColorAnimPlugin::loadBrainModels(const std::string &basePath)
231268
for (int i = 0; i < numFrames; ++i)
232269
{
233270
std::ostringstream modelPath;
234-
modelPath << basePath << "highres_cortex_" << std::setfill('0') << std::setw(3) << (i + 1) << ".ply";
271+
modelPath << directory << baseFileName << std::setfill('0') << std::setw(numberWidth)
272+
<< (startNumber + i) << extension;
235273

236274
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile(modelPath.str());
237275

src/OpenCOVER/plugins/ukoeln/colorAnim/ColorAnimPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ColorAnimPlugin : public coVRPlugin, public ui::Owner
8181
InterpolationMode interpolationMode;
8282

8383
// Helper methods
84-
bool loadBrainModels(const std::string &path);
84+
bool loadBrainModels(const std::string &firstFilePath);
8585
void updateColors();
8686
osg::Vec4Array* interpolateColors(int frame1, int frame2, float t);
8787
void flipNormals();

0 commit comments

Comments
 (0)