// add a name to the upgrader lookup dict. static void soupgrader_add_to_namedict(const SbString & name) { assert(soupgrader_namedict); // Note: the SbString->SbName wrapping is necessary, or the const // char* will _not_ be valid upon the SbString going out of scope // (while SbName makes permanent const char* references). soupgrader_namedict->put(SbName(name.getString()).getString(), NULL); // Create lookup both with and without the "So" prefix. This is // necessary for the hash lookup in soupgrader_exists() to match // with both permutations. SbString tmp; if (name.compareSubString("So") == 0) { tmp = name.getSubString(2); } else { tmp = "So"; tmp += name; } // Note: the SbString->SbName wrapping is necessary, see above // comment. soupgrader_namedict->put(SbName(tmp.getString()).getString(), NULL); }
void IKRRTWindow::saveScreenshot() { static int counter = 0; SbString framefile; framefile.sprintf("renderFrame_%06d.png", counter); counter++; redraw(); viewer->getSceneManager()->render(); viewer->getSceneManager()->scheduleRedraw(); QGLWidget* w = (QGLWidget*)viewer->getGLWidget(); QImage i = w->grabFrameBuffer(); bool bRes = i.save(framefile.getString(), "BMP"); if (bRes) { cout << "wrote image " << counter << endl; } else { cout << "failed writing image " << counter << endl; } }
SbBool writeImage( const char* file, unsigned int offset, SbXipImage& image ) { #ifdef WIN32 //assuming everything is done using the bad backslashes... so we convert all forward slashes to those const char * fileLocal = XipReplaceChar(file, '/', '\\').getString(); #else //UNIX //assuming the other way around since we need forward slashes now... const char * fileLocal = XipReplaceChar(file, '\\', '/').getString(); #endif //WIN32 int r = 0; void* imageBufferPtr = image.refBufferPtr(); if( imageBufferPtr ) { SbString path = XipStrExpandEnv( fileLocal ); FILE* fs = fopen( path.getString(), "wb" ); if (!fs) return FALSE; fseek( fs, offset, SEEK_SET ); r = fwrite(imageBufferPtr, 1, image.bufferSize(), fs ); fclose( fs ); } image.unrefBufferPtr(); return (r == image.bufferSize()); }
/** * Creates a point element as visible feedback for the user. */ SoNode* ManualAlignment::pickedPointsSubGraph(const SbVec3f& p, const SbVec3f& n, int id) { static const float color_table [10][3] = { {1.0f,0.0f,0.0f}, // red {0.0f,1.0f,0.0f}, // green {0.0f,0.0f,1.0f}, // blue {1.0f,1.0f,0.0f}, // yellow {0.0f,1.0f,1.0f}, // cyan {0.7f,0.0f,0.0f}, {0.0f,0.7f,0.0f}, {0.7f,0.7f,0.0f}, {0.7f,0.0f,0.5f}, {1.0f,0.7f,0.0f} }; int index = (id-1) % 10; SoRegPoint* probe = new SoRegPoint(); probe->base.setValue(p); probe->normal.setValue(n); probe->color.setValue(color_table[index][0],color_table[index][1],color_table[index][2]); SbString s; probe->text.setValue(s.sprintf("RegPoint_%d", id)); return probe; }
void SoXipImageOverlayManager::updateSliceMap() { // Removes all the previous entries mSliceMap.clear(); SoSearchAction sa; sa.setInterest( SoSearchAction::ALL ); sa.setType( SoXipShapeList::getClassTypeId() ); sa.setSearchingAll( TRUE ); sa.apply( mShapeSwitch ); SoPathList paths = sa.getPaths(); for( int i = 0; i < paths.getLength(); ++ i ) { SbString label = ((SoXipShapeList *) paths[i]->getTail())->label.getValue().getString(); int sliceIndex; if( sscanf( label.getString(), "%d", &sliceIndex ) != 1 ) { SoDebugError::post( __FILE__, "Invalid label found '%s'", label.getString() ); continue ; } mSliceMap[ sliceIndex ] = (SoXipShapeList *) paths[i]->getTail(); } }
void SoXipImageOverlayManager::loadOverlays() { // When the patient changes clearClipboard(); // Remove all the geometries from the switch mShapeSwitch->removeAllChildren(); mShapeSwitch->whichChild.setValue(-1); mCurrentSlice = -1; if( mImageData ) { SbString overlayStr = mImageData->getProperty( "overlays" ); SoNodeList nodes = XipOverlayUtils::loadOverlaysFromString( overlayStr.getString(), overlayStr.getLength(), TRUE ); for( int i = 0; i < nodes.getLength(); ++ i ) { if( !nodes[i]->isOfType( SoXipShapeList::getClassTypeId() ) ) { SoDebugError::post( __FILE__, "Invalid overlay node found in Dicom. Ignored." ); continue ; } mShapeSwitch->addChild( nodes[i] ); } } updateSliceMap(); }
// Documented in superclass. Overridden to pass GL state to the // previous element. void SoGLMultiTextureImageElement::pop(SoState * state, const SoElement * prevTopElement) { inherited::pop(state, prevTopElement); SoGLMultiTextureImageElement * prev = (SoGLMultiTextureImageElement*) prevTopElement; SoGLShaderProgram * prog = SoGLShaderProgramElement::get(state); SbString str; const int maxunits = SbMax(PRIVATE(prev)->unitdata.getLength(), PRIVATE(this)->unitdata.getLength()); for (int i = 0; i < maxunits; i++) { const GLUnitData & prevud = (i < PRIVATE(prev)->unitdata.getLength()) ? PRIVATE(prev)->unitdata[i] : PRIVATE(prev)->defaultdata; const GLUnitData & thisud = (i < PRIVATE(this)->unitdata.getLength()) ? PRIVATE(this)->unitdata[i] : PRIVATE(this)->defaultdata; if (thisud.glimage != prevud.glimage) this->updateGL(i); str.sprintf("coin_texunit%d_model", i); if (prog) prog->updateCoinParameter(state, SbName(str.getString()), thisud.glimage != NULL ? this->getUnitData(i).model : 0); } }
void SoVRMLAudioClipP::loadUrl() { #ifdef HAVE_THREADS SbThreadAutoLock autoLock(&this->syncmutex); #endif this->unloadUrl(); for (int i=0; i<PUBLIC(this)->url.getNum(); i++) { const char * str = PUBLIC(this)->url[i].getString(); if ( (str == NULL) || (strlen(str)==0) ) continue; // ignore empty url SbString filename = SoInput::searchForFile(SbString(str), SoInput::getDirectories(), SoVRMLAudioClip::getSubdirectories()); if (filename.getLength() <= 0) { SoDebugError::postWarning("SoVRMLAudioClipP::loadUrl(index)", "File not found: '%s'", str); continue; // ignore invalid file } this->playlist.append(filename); } }
void errorHandlerCB(const SoError * error, void * data) { if (pipeErrorMessagesToConsole) { (void)printf("%s\n", error->getDebugString().getString()); } else { SbString debugstring = error->getDebugString(); ::MessageBox(NULL, CHAR_TO_NATIVE(debugstring.getString()), TEXT("SoError"), MB_OK | MB_ICONERROR); } }
SoCallbackAction::Response SoToVRMLActionP::unsupported_cb(void * closure, SoCallbackAction * COIN_UNUSED_ARG(action), const SoNode * node) { SoInfo * info = NEW_NODE(SoInfo, node); SbString str; str.sprintf("Unsupported node: %s", node->getTypeId().getName().getString()); info->string = str; THISP(closure)->get_current_tail()->addChild(info); return SoCallbackAction::CONTINUE; }
void ViewProviderVRMLObject::addResource(const SbString& url, std::list<std::string>& resources) { SbString found = SoInput::searchForFile(url, SoInput::getDirectories(), SbStringList()); Base::FileInfo fi(found.getString()); if (fi.exists()) { // add the resource file if not yet listed if (std::find(resources.begin(), resources.end(), found.getString()) == resources.end()) { resources.push_back(found.getString()); } } }
/*! Sets the current texture. Id \a didapply is TRUE, it is assumed that the texture image already is the current GL texture. Do not use this feature unless you know what you're doing. */ void SoGLMultiTextureImageElement::set(SoState * const state, SoNode * const node, const int unit, SoGLImage * image, Model model, const SbColor & blendColor) { SoGLMultiTextureImageElement * elem = (SoGLMultiTextureImageElement*) state->getElement(classStackIndex); PRIVATE(elem)->ensureCapacity(unit); GLUnitData & ud = PRIVATE(elem)->unitdata[unit]; // FIXME: buggy. Find some solution to handle this. pederb, 2003-11-12 // if (ud.glimage && ud.glimage->getImage()) ud.glimage->getImage()->readUnlock(); if (image) { // keep SoMultiTextureImageElement "up-to-date" inherited::set(state, node, unit, SbVec3s(0,0,0), 0, NULL, multi_translateWrap(image->getWrapS()), multi_translateWrap(image->getWrapT()), multi_translateWrap(image->getWrapR()), model, blendColor); ud.glimage = image; // make sure image isn't changed while this is the active texture // FIXME: buggy. Find some solution to handle this. pederb, 2003-11-12 // if (image->getImage()) image->getImage()->readLock(); } else { ud.glimage = NULL; inherited::setDefault(state, node, unit); } elem->updateGL(unit); // FIXME: check if it's possible to support for other units as well if ((unit == 0) && image && image->isOfType(SoGLBigImage::getClassTypeId())) { SoShapeStyleElement::setBigImageEnabled(state, TRUE); } SoShapeStyleElement::setTransparentTexture(state, SoGLMultiTextureImageElement::hasTransparency(state)); SoGLShaderProgram * prog = SoGLShaderProgramElement::get(state); if (prog) { SbString str; str.sprintf("coin_texunit%d_model", unit); prog->updateCoinParameter(state, SbName(str.getString()), ud.glimage ? model : 0); } }
QVariant ParametersItem::data ( int role ) const { if( role == Qt::DisplayRole ) { if ( column() == 0 ) return m_text; SbString fieldValue = "null"; m_pField->get( fieldValue ); return QString( fieldValue.getString() ); } else return QStandardItem::data( role ); }
void SoView2DLiftChart::drawSliceIndicator(int x1, int x2, int y, int slice) { glColor3f(1, 1, 1); glBegin(GL_LINES); glVertex2f(x1, y - 1); glVertex2f(x2 + 6, y - 1); glEnd(); // convert float distance to string SbString sliceString = float(slice); View2DFont* font = SoView2D::globalFont(_dsl->getCurrentCacheContext()); float fcolor[4] = {color.getValue()[0],color.getValue()[1],color.getValue()[2],1}; font->drawString(x2 + 10, y - 6, 12, fcolor, sliceString.getString(), 0, true); }
SbString SbString::getSubString(int startChar, int endChar) const { int len = getLength(); // Get substring that starts at specified character SbString tmp = &string[startChar]; // Delete characters from end if necessary if (endChar >= 0 && endChar < len - 1) tmp.deleteSubString(endChar - startChar + 1); return tmp; }
void SoXipImageOverlayManager::addOverlays() { const SoNode** nodes = overlays.getValues(0); for( int i = 0; i < overlays.getNum(); ++ i ) { const SoXipShapeList* shapeList = (const SoXipShapeList *) nodes[i]; if( !shapeList->isOfType( SoXipShapeList::getClassTypeId() ) ) { SoDebugError::post( __FILE__, "Child not supported" ); return ; } int sliceIndex; if( sscanf( shapeList->label.getValue().getString(), "%d", &sliceIndex ) != 1 ) { SoDebugError::post( __FILE__, "Invalid label found '%s'", shapeList->label.getValue().getString() ); return ; } SoXipShapeList* sliceShapeList = mSliceMap[ sliceIndex ]; if( !sliceShapeList ) { sliceShapeList = new SoXipShapeList; sliceShapeList->label.setValue( SbString( sliceIndex ) ); mShapeSwitch->addChild( sliceShapeList ); mSliceMap[ sliceIndex ] = sliceShapeList; } int numShapes = shapeList->getNumChildren(); for( int i = 0; i < numShapes; ++ i ) { // Copy to string to force removing of the connections SoNode* copyNode = shapeList->getChild (i)->copy(); copyNode->ref(); SbString str = XipOverlayUtils::saveNodeToString( copyNode ); copyNode->unref(); // Reload copy node from this string SoNode* readNode = XipOverlayUtils::loadNodeFromString( str.getString(), str.getLength() ); ((SoXipShape *) readNode)->updateGeometries(); sliceShapeList->addChild( readNode ); } } }
__uint64 SoXipGLSLShaderProgramElement::getTimeStamp(SoState * const state, const SbString & prgTag) { ShaderProgramManager * manager = ShaderProgramManager::getInstance(); __uint64 time = manager->getTimeStamp(prgTag.getString()); return time; }
int SoXipGLSLShaderProgramElement::getProgramID(SoState * const state, const SbString & prgTag) { ShaderProgramManager * manager = ShaderProgramManager::getInstance(); int prgHandle = manager->getProgramHandle(prgTag.getString()); return prgHandle; }
SbString SoGLARBShaderProgram::getSourceHint(void) const { SbString result; if (this->fragmentShader && this->fragmentShader->isActive()) { SbString str = this->fragmentShader->sourceHint; if (str.getLength() > 0) str += " "; result += str; } if (this->vertexShader && this->vertexShader->isActive()) { SbString str = this->vertexShader->sourceHint; if (str.getLength() > 0) str += " "; result += str; } return result; }
void SoXipGLSLPrograms::setTimeStamps(ShaderBatch * batch, const SbString& filename) { if (!batch) return; int tod = ShaderEngine::getSourceFileTimeStamp(filename.getString()); batch->source.setSourceTimeStamp(tod); batch->dirtyTimestamp = false; }
void ScXMLStringDataObj::convertToString(SbString & str) const { if (!this->value) { str = "''"; } else { // FIXME: quote special characters (') str.sprintf("'%s'", this->value); } }
void QCtkXipSGWidget::updateCursor(bool fromScene) { if (fromScene) { if (!mCursorField) { mCursorField = SoDB::getGlobalField(SbName("MouseCursor")); } if (mCursorField) { SbString str; mCursorField->get(str); const char *handlePtr = strstr(str.getString(), "handle\t"); if (handlePtr) { void *handle = 0; if (sscanf(handlePtr, "handle\t%p", &handle) == 1) { if (handle) { #ifdef WIN32 setCursor(QCursor((HCURSOR) handle)); #endif /* WIN32 */ #ifdef linux setCursor(QCursor((Qt::HANDLE) handle)); #endif /* LINUX */ #ifdef DARWIN setCursor(QCursor()); // FIXME: We must create a handle for Mac OS X #endif /* DARWIN */ return; } } } } } setCursor(Qt::ArrowCursor); }
int SoXipGLSLShaderProgramElement::set(SoState * const state, const SbString & prgTag) { ShaderProgramManager * manager = ShaderProgramManager::getInstance(); int prgHandle = manager->getProgramHandle(prgTag.getString()); SoInt32Element::set(classStackIndex, state, prgHandle); return prgHandle; }
/*! Creates an instance of a suitable SoForeignFileKit subtype. Returns NULL on failure or a kit with refcount of 1 on success. */ static SoForeignFileKit *create_foreignfilekit(const char *filename, SbBool exhaust) { assert(SoForeignFileKitP::fileexts != NULL); const char * extptr = strrchr(filename, '.'); if (extptr) { extptr++; SbName ext(SbString(extptr).lower()); SoType handler = SoType::badType(); if (SoForeignFileKitP::fileexts->get(ext.getString(), handler)) { SoForeignFileKit * foreignfile = (SoForeignFileKit *)handler.createInstance(); foreignfile->ref(); if (foreignfile->canReadFile(filename)) { return foreignfile; } else { foreignfile->unref(); } } else { // We try to synthesize a classname from the extension (e.g. SoFBXFileKit), // and load it using the SoType autoloader feature. SbString filekitname; filekitname.sprintf("So%sFileKit", SbString(ext.getString()).upper().getString()); SoType filekittype = SoType::fromName(SbName(filekitname)); if (!filekittype.isBad()) return create_foreignfilekit(filename, exhaust); // FIXME: Some filekits supports more than one file format/extension (e.g. FBX). // We need a way of mapping extensions to library, or a way of loading // each external kit and testing for support. // FIXME: Temporary hack: Load SoFBXFileKit filekitname = "SoFBXFileKit"; filekittype = SoType::fromName(SbName(filekitname)); if (!filekittype.isBad()) return create_foreignfilekit(filename, exhaust); } } if (exhaust) { // FIXME: Implement // SoForeignFileKitP::fileexts->apply() } return NULL; }
SbBool SoTexture2::readImage(const SbString& fname, int &w, int &h, int &nc, unsigned char *&bytes) // //////////////////////////////////////////////////////////////////////// { w = h = nc = 0; bytes = NULL; // Empty file means an empty image... if (fname.getString()[0] == '\0') return TRUE; SoInput in; if (!in.openFile(fname.getString(), TRUE)) { return FALSE; } #ifdef DEBUG SoDebugError::postInfo("SoTexture2::readImage", "Reading texture image %s", fname.getString()); #endif if (ReadSGIImage(in, w, h, nc, bytes)) return TRUE; // fiopen() closes the file even if it can't read the data, so // reopen it in.closeFile(); if (!in.openFile(fname.getString(), TRUE)) return FALSE; if (ReadGIFImage(in, w, h, nc, bytes)) return TRUE; if (ReadJPEGImage(in, w, h, nc, bytes)) return TRUE; return FALSE; }
LRESULT SoSimple::onQuit(HWND window, UINT message, WPARAM wparam, LPARAM lparam) { if (idleSensorId != 0) ::KillTimer(NULL, idleSensorId); if (timerSensorId != 0) ::KillTimer(NULL, timerSensorId); if (delaySensorId != 0) ::KillTimer(NULL, delaySensorId); idleSensorId = timerSensorId = delaySensorId = 0; ::UnregisterClass(CHAR_TO_NATIVE(gClassName.getString()), NULL); return 0; }
void SoHandleBoxDragger::updateArrows(void) { int i; SbString str; SoSwitch *sw; if (this->constraintState >= CONSTRAINT_X) { int onval = -1; switch (this->constraintState) { case CONSTRAINT_X: onval = 3; break; case CONSTRAINT_Y: onval = 1; break; case CONSTRAINT_Z: onval = 5; break; } for (i = 1; i <= 6; i++) { str.sprintf("arrow%dSwitch", i); sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch); if (i == onval || i == onval + 1) { SoInteractionKit::setSwitchValue(sw, 0); } else { SoInteractionKit::setSwitchValue(sw, SO_SWITCH_NONE); } } } else if (this->whatkind == WHATKIND_TRANSLATOR) { int num = (this->whatnum-1) & ~1; for (i = 0; i < 6; i++) { str.sprintf("arrow%dSwitch", i+1); sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch); if (i == num || i == num+1) { SoInteractionKit::setSwitchValue(sw, SO_SWITCH_NONE); } else { SoInteractionKit::setSwitchValue(sw, 0); } } } else { for (i = 1; i <= 6; i++) { str.sprintf("arrow%dSwitch", i); sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch); SoInteractionKit::setSwitchValue(sw, SO_SWITCH_NONE); } } }
bool SoXipGLSLPrograms::checkTimeStamps(ShaderBatch * batch, const SbString& filename) { if (!batch) return false; bool dirty = false; int tod = ShaderEngine::getSourceFileTimeStamp(filename.getString()); int sts = batch->source.getSourceTimeStamp(); if (tod > sts) dirty = true; batch->dirtyTimestamp = dirty; return dirty; }
bool SoMap2ImagePt::getMappingPoint(int pt[2], SbString &uid, SbVec3f point) { int depth = refInput.getNum(); int slice = (int)(point[2] * depth); if (slice < 0 || slice >= depth) return false; SoXipDataDicom *dicom = refInput[slice]; if (dicom){ if (!dicom->getDataset().isNull()){ SbXipDicomItem dataset(dicom->getDataset()); //sop instance UID dataset.findAndGet(SbXipDicomTagKey(0x08, 0x18), uid, true); SbString imageCols; //image col dataset.findAndGet(SbXipDicomTagKey(0x0028, 0x0011), imageCols, true); SbString imageRows; //image row dataset.findAndGet(SbXipDicomTagKey(0x0028, 0x0010), imageRows, true); int col = atoi(imageCols.getString()); int row = atoi(imageRows.getString()); pt[0] = (int)(point[0] * col + 0.5); pt[1] = (int)(point[1] * row + 0.5); return true; } } return false; }
void SoXipData::setProperty(const SbString &key, const SbString &value) { if (key.getLength() == 0) { SoDebugError::postWarning("SoXipData::setProperty", "Key is empty! The value cannot be stored."); return; } if (!mProperties) { mProperties = new SbXipDataPropertyMap; if (!mProperties) { SoMemoryError::post("SbXipDataPropertyMap"); return; } } (*mProperties)[key] = value; }