diff --git a/Core/Code/Controllers/mitkCoreActivator.cpp b/Core/Code/Controllers/mitkCoreActivator.cpp index 4d48b15f83..052a3aa8a7 100644 --- a/Core/Code/Controllers/mitkCoreActivator.cpp +++ b/Core/Code/Controllers/mitkCoreActivator.cpp @@ -1,213 +1,209 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkRenderingManager.h" #include "mitkPlanePositionManager.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void HandleMicroServicesMessages(us::MsgType type, const char* msg) { switch (type) { case us::DebugMsg: MITK_DEBUG << msg; break; case us::InfoMsg: MITK_INFO << msg; break; case us::WarningMsg: MITK_WARN << msg; break; case us::ErrorMsg: MITK_ERROR << msg; break; } } void AddMitkAutoLoadPaths(const std::string& programPath) { us::ModuleSettings::AddAutoLoadPath(programPath); #ifdef __APPLE__ // Walk up three directories since that is where the .dylib files are located // for build trees. std::string additionalPath = programPath; bool addPath = true; for(int i = 0; i < 3; ++i) { std::size_t index = additionalPath.find_last_of('/'); if (index != std::string::npos) { additionalPath = additionalPath.substr(0, index); } else { addPath = false; break; } } if (addPath) { us::ModuleSettings::AddAutoLoadPath(additionalPath); } #endif } /* * This is the module activator for the "Mitk" module. It registers core services * like ... */ class MitkCoreActivator : public us::ModuleActivator { public: void Load(us::ModuleContext* context) { // Handle messages from CppMicroServices us::installMsgHandler(HandleMicroServicesMessages); // Add the current application directory to the auto-load paths. // This is useful for third-party executables. std::string programPath = mitk::IOUtil::GetProgramPath(); if (programPath.empty()) { MITK_WARN << "Could not get the program path."; } else { AddMitkAutoLoadPaths(programPath); } //m_RenderingManager = mitk::RenderingManager::New(); //context->RegisterService(renderingManager.GetPointer()); m_PlanePositionManager.reset(new mitk::PlanePositionManagerService); context->RegisterService(m_PlanePositionManager.get()); m_CoreDataNodeReader.reset(new mitk::CoreDataNodeReader); context->RegisterService(m_CoreDataNodeReader.get()); - m_ShaderRepository.reset(new mitk::ShaderRepository); - context->RegisterService(m_ShaderRepository.get()); - m_PropertyAliases.reset(new mitk::PropertyAliases); context->RegisterService(m_PropertyAliases.get()); m_PropertyDescriptions.reset(new mitk::PropertyDescriptions); context->RegisterService(m_PropertyDescriptions.get()); m_PropertyExtensions.reset(new mitk::PropertyExtensions); context->RegisterService(m_PropertyExtensions.get()); m_PropertyFilters.reset(new mitk::PropertyFilters); context->RegisterService(m_PropertyFilters.get()); context->AddModuleListener(this, &MitkCoreActivator::HandleModuleEvent); /* There IS an option to exchange ALL vtkTexture instances against vtkNeverTranslucentTextureFactory. This code is left here as a reminder, just in case we might need to do that some time. vtkNeverTranslucentTextureFactory* textureFactory = vtkNeverTranslucentTextureFactory::New(); vtkObjectFactory::RegisterFactory( textureFactory ); textureFactory->Delete(); */ } void Unload(us::ModuleContext* ) { // The mitk::ModuleContext* argument of the Unload() method // will always be 0 for the Mitk library. It makes no sense // to use it at this stage anyway, since all libraries which // know about the module system have already been unloaded. } private: void HandleModuleEvent(const us::ModuleEvent moduleEvent); std::map > moduleIdToShaderIds; //mitk::RenderingManager::Pointer m_RenderingManager; std::auto_ptr m_PlanePositionManager; std::auto_ptr m_CoreDataNodeReader; - std::auto_ptr m_ShaderRepository; std::auto_ptr m_PropertyAliases; std::auto_ptr m_PropertyDescriptions; std::auto_ptr m_PropertyExtensions; std::auto_ptr m_PropertyFilters; }; void MitkCoreActivator::HandleModuleEvent(const us::ModuleEvent moduleEvent) { if (moduleEvent.GetType() == us::ModuleEvent::LOADED) { // search and load shader files std::vector shaderResoruces = moduleEvent.GetModule()->FindResources("Shaders", "*.xml", true); for (std::vector::iterator i = shaderResoruces.begin(); i != shaderResoruces.end(); ++i) { if (*i) { us::ModuleResourceStream rs(*i); - int id = m_ShaderRepository->LoadShader(rs, i->GetBaseName()); - if (id >= 0) - { - moduleIdToShaderIds[moduleEvent.GetModule()->GetModuleId()].push_back(id); - } +// int id = m_ShaderRepository->LoadShader(rs, i->GetBaseName()); +// if (id >= 0) +// { +// moduleIdToShaderIds[moduleEvent.GetModule()->GetModuleId()].push_back(id); +// } } } } else if (moduleEvent.GetType() == us::ModuleEvent::UNLOADED) { std::map >::iterator shaderIdsIter = moduleIdToShaderIds.find(moduleEvent.GetModule()->GetModuleId()); if (shaderIdsIter != moduleIdToShaderIds.end()) { - for (std::vector::iterator idIter = shaderIdsIter->second.begin(); - idIter != shaderIdsIter->second.end(); ++idIter) - { - m_ShaderRepository->UnloadShader(*idIter); - } - moduleIdToShaderIds.erase(shaderIdsIter); +// for (std::vector::iterator idIter = shaderIdsIter->second.begin(); +// idIter != shaderIdsIter->second.end(); ++idIter) +// { +// m_ShaderRepository->UnloadShader(*idIter); +// } +// moduleIdToShaderIds.erase(shaderIdsIter); } } } US_EXPORT_MODULE_ACTIVATOR(Mitk, MitkCoreActivator) // Call CppMicroservices initialization code at the end of the file. // This especially ensures that VTK object factories have already // been registered (VTK initialization code is injected by implicitly // include VTK header files at the top of this file). US_INITIALIZE_MODULE("Mitk", "Mitk") diff --git a/Core/Code/files.cmake b/Core/Code/files.cmake index c991bfedc4..acf24d2ad0 100644 --- a/Core/Code/files.cmake +++ b/Core/Code/files.cmake @@ -1,407 +1,403 @@ set(H_FILES Algorithms/itkImportMitkImageContainer.h Algorithms/itkImportMitkImageContainer.txx Algorithms/itkLocalVariationImageFilter.h Algorithms/itkLocalVariationImageFilter.txx Algorithms/itkMITKScalarImageToHistogramGenerator.h Algorithms/itkMITKScalarImageToHistogramGenerator.txx Algorithms/itkTotalVariationDenoisingImageFilter.h Algorithms/itkTotalVariationDenoisingImageFilter.txx Algorithms/itkTotalVariationSingleIterationImageFilter.h Algorithms/itkTotalVariationSingleIterationImageFilter.txx Algorithms/mitkBilateralFilter.h Algorithms/mitkBilateralFilter.cpp Algorithms/mitkInstantiateAccessFunctions.h Algorithms/mitkPixelTypeList.h Algorithms/mitkPPArithmeticDec.h Algorithms/mitkPPArgCount.h Algorithms/mitkPPCat.h Algorithms/mitkPPConfig.h Algorithms/mitkPPControlExprIIf.h Algorithms/mitkPPControlIf.h Algorithms/mitkPPControlIIf.h Algorithms/mitkPPDebugError.h Algorithms/mitkPPDetailAutoRec.h Algorithms/mitkPPDetailDMCAutoRec.h Algorithms/mitkPPExpand.h Algorithms/mitkPPFacilitiesEmpty.h Algorithms/mitkPPFacilitiesExpand.h Algorithms/mitkPPLogicalBool.h Algorithms/mitkPPRepetitionDetailDMCFor.h Algorithms/mitkPPRepetitionDetailEDGFor.h Algorithms/mitkPPRepetitionDetailFor.h Algorithms/mitkPPRepetitionDetailMSVCFor.h Algorithms/mitkPPRepetitionFor.h Algorithms/mitkPPSeqElem.h Algorithms/mitkPPSeqForEach.h Algorithms/mitkPPSeqForEachProduct.h Algorithms/mitkPPSeq.h Algorithms/mitkPPSeqEnum.h Algorithms/mitkPPSeqSize.h Algorithms/mitkPPSeqToTuple.h Algorithms/mitkPPStringize.h Algorithms/mitkPPTupleEat.h Algorithms/mitkPPTupleElem.h Algorithms/mitkPPTupleRem.h Algorithms/mitkClippedSurfaceBoundsCalculator.h Algorithms/mitkExtractSliceFilter.h Algorithms/mitkConvert2Dto3DImageFilter.h Algorithms/mitkPlaneClipping.h Common/mitkCommon.h Common/mitkExceptionMacro.h DataManagement/mitkProportionalTimeGeometry.h DataManagement/mitkTimeGeometry.h DataManagement/mitkImageAccessByItk.h DataManagement/mitkImageCast.h DataManagement/mitkImagePixelAccessor.h DataManagement/mitkImagePixelReadAccessor.h DataManagement/mitkImagePixelWriteAccessor.h DataManagement/mitkImageReadAccessor.h DataManagement/mitkImageWriteAccessor.h DataManagement/mitkITKImageImport.h DataManagement/mitkITKImageImport.txx DataManagement/mitkImageToItk.h DataManagement/mitkImageToItk.txx DataManagement/mitkTimeSlicedGeometry.h # Deprecated, empty for compatibilty reasons. Interactions/mitkEventMapperAddOn.h Interfaces/mitkIDataNodeReader.h Rendering/mitkLocalStorageHandler.h IO/mitkPixelTypeTraits.h ) set(CPP_FILES Algorithms/mitkBaseDataSource.cpp Algorithms/mitkCompareImageDataFilter.cpp Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp Algorithms/mitkDataNodeSource.cpp Algorithms/mitkGeometry2DDataToSurfaceFilter.cpp Algorithms/mitkHistogramGenerator.cpp Algorithms/mitkImageChannelSelector.cpp Algorithms/mitkImageSliceSelector.cpp Algorithms/mitkImageSource.cpp Algorithms/mitkImageTimeSelector.cpp Algorithms/mitkImageToImageFilter.cpp Algorithms/mitkImageToSurfaceFilter.cpp Algorithms/mitkPointSetSource.cpp Algorithms/mitkPointSetToPointSetFilter.cpp Algorithms/mitkRGBToRGBACastImageFilter.cpp Algorithms/mitkSubImageSelector.cpp Algorithms/mitkSurfaceSource.cpp Algorithms/mitkSurfaceToImageFilter.cpp Algorithms/mitkSurfaceToSurfaceFilter.cpp Algorithms/mitkUIDGenerator.cpp Algorithms/mitkVolumeCalculator.cpp Algorithms/mitkClippedSurfaceBoundsCalculator.cpp Algorithms/mitkExtractSliceFilter.cpp Algorithms/mitkConvert2Dto3DImageFilter.cpp Controllers/mitkBaseController.cpp Controllers/mitkCallbackFromGUIThread.cpp Controllers/mitkCameraController.cpp Controllers/mitkCameraRotationController.cpp Controllers/mitkCoreActivator.cpp Controllers/mitkFocusManager.cpp Controllers/mitkLimitedLinearUndo.cpp Controllers/mitkOperationEvent.cpp Controllers/mitkPlanePositionManager.cpp Controllers/mitkProgressBar.cpp Controllers/mitkRenderingManager.cpp Controllers/mitkSliceNavigationController.cpp Controllers/mitkSlicesCoordinator.cpp Controllers/mitkSlicesRotator.cpp Controllers/mitkSlicesSwiveller.cpp Controllers/mitkStatusBar.cpp Controllers/mitkStepper.cpp Controllers/mitkTestManager.cpp Controllers/mitkUndoController.cpp Controllers/mitkVerboseLimitedLinearUndo.cpp Controllers/mitkVtkInteractorCameraController.cpp Controllers/mitkVtkLayerController.cpp DataManagement/mitkProportionalTimeGeometry.cpp DataManagement/mitkTimeGeometry.cpp DataManagement/mitkAbstractTransformGeometry.cpp DataManagement/mitkAnnotationProperty.cpp DataManagement/mitkApplicationCursor.cpp DataManagement/mitkBaseData.cpp DataManagement/mitkBaseProperty.cpp DataManagement/mitkClippingProperty.cpp DataManagement/mitkChannelDescriptor.cpp DataManagement/mitkColorProperty.cpp DataManagement/mitkDataStorage.cpp # DataManagement/mitkDataTree.cpp DataManagement/mitkDataNode.cpp DataManagement/mitkDataNodeFactory.cpp # DataManagement/mitkDataTreeStorage.cpp DataManagement/mitkDisplayGeometry.cpp DataManagement/mitkEnumerationProperty.cpp DataManagement/mitkGeometry2D.cpp DataManagement/mitkGeometry2DData.cpp DataManagement/mitkGeometry3D.cpp DataManagement/mitkGeometryData.cpp DataManagement/mitkGroupTagProperty.cpp DataManagement/mitkImage.cpp DataManagement/mitkImageAccessorBase.cpp DataManagement/mitkImageCaster.cpp DataManagement/mitkImageCastPart1.cpp DataManagement/mitkImageCastPart2.cpp DataManagement/mitkImageCastPart3.cpp DataManagement/mitkImageCastPart4.cpp DataManagement/mitkImageDataItem.cpp DataManagement/mitkImageDescriptor.cpp DataManagement/mitkImageVtkAccessor.cpp DataManagement/mitkImageStatisticsHolder.cpp DataManagement/mitkLandmarkBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjectorBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjector.cpp DataManagement/mitkLevelWindow.cpp DataManagement/mitkLevelWindowManager.cpp DataManagement/mitkLevelWindowPreset.cpp DataManagement/mitkLevelWindowProperty.cpp DataManagement/mitkLookupTable.cpp DataManagement/mitkLookupTables.cpp # specializations of GenericLookupTable DataManagement/mitkMemoryUtilities.cpp DataManagement/mitkModalityProperty.cpp DataManagement/mitkModeOperation.cpp DataManagement/mitkNodePredicateAnd.cpp DataManagement/mitkNodePredicateBase.cpp DataManagement/mitkNodePredicateCompositeBase.cpp DataManagement/mitkNodePredicateData.cpp DataManagement/mitkNodePredicateDataType.cpp DataManagement/mitkNodePredicateDimension.cpp DataManagement/mitkNodePredicateFirstLevel.cpp DataManagement/mitkNodePredicateNot.cpp DataManagement/mitkNodePredicateOr.cpp DataManagement/mitkNodePredicateProperty.cpp DataManagement/mitkNodePredicateSource.cpp DataManagement/mitkPlaneOrientationProperty.cpp DataManagement/mitkPlaneGeometry.cpp DataManagement/mitkPlaneOperation.cpp DataManagement/mitkPointOperation.cpp DataManagement/mitkPointSet.cpp DataManagement/mitkProperties.cpp DataManagement/mitkPropertyList.cpp DataManagement/mitkPropertyObserver.cpp DataManagement/mitkRestorePlanePositionOperation.cpp DataManagement/mitkApplyTransformMatrixOperation.cpp DataManagement/mitkRotationOperation.cpp DataManagement/mitkSlicedData.cpp DataManagement/mitkSlicedGeometry3D.cpp DataManagement/mitkSmartPointerProperty.cpp DataManagement/mitkStandaloneDataStorage.cpp DataManagement/mitkStateTransitionOperation.cpp DataManagement/mitkStringProperty.cpp DataManagement/mitkSurface.cpp DataManagement/mitkSurfaceOperation.cpp DataManagement/mitkThinPlateSplineCurvedGeometry.cpp DataManagement/mitkTransferFunction.cpp DataManagement/mitkTransferFunctionProperty.cpp DataManagement/mitkTransferFunctionInitializer.cpp DataManagement/mitkVector.cpp DataManagement/mitkVtkInterpolationProperty.cpp DataManagement/mitkVtkRepresentationProperty.cpp DataManagement/mitkVtkResliceInterpolationProperty.cpp DataManagement/mitkVtkScalarModeProperty.cpp DataManagement/mitkVtkVolumeRenderingProperty.cpp DataManagement/mitkWeakPointerProperty.cpp DataManagement/mitkRenderingModeProperty.cpp - DataManagement/mitkShaderProperty.cpp DataManagement/mitkResliceMethodProperty.cpp DataManagement/mitkMaterial.cpp DataManagement/mitkPointSetShapeProperty.cpp DataManagement/mitkFloatPropertyExtension.cpp DataManagement/mitkIntPropertyExtension.cpp DataManagement/mitkPropertyExtension.cpp DataManagement/mitkPropertyFilter.cpp DataManagement/mitkPropertyAliases.cpp DataManagement/mitkPropertyDescriptions.cpp DataManagement/mitkPropertyExtensions.cpp DataManagement/mitkPropertyFilters.cpp Interactions/mitkAction.cpp Interactions/mitkAffineInteractor.cpp Interactions/mitkBindDispatcherInteractor.cpp Interactions/mitkCoordinateSupplier.cpp Interactions/mitkDataInteractor.cpp Interactions/mitkDispatcher.cpp Interactions/mitkDisplayCoordinateOperation.cpp Interactions/mitkDisplayInteractor.cpp Interactions/mitkDisplayPositionEvent.cpp # Interactions/mitkDisplayVectorInteractorLevelWindow.cpp # legacy, prob even now unneeded # Interactions/mitkDisplayVectorInteractorScroll.cpp Interactions/mitkEvent.cpp Interactions/mitkEventConfig.cpp Interactions/mitkEventDescription.cpp Interactions/mitkEventFactory.cpp Interactions/mitkInteractionEventHandler.cpp Interactions/mitkEventMapper.cpp Interactions/mitkEventStateMachine.cpp Interactions/mitkGlobalInteraction.cpp Interactions/mitkInteractor.cpp Interactions/mitkInternalEvent.cpp Interactions/mitkInteractionEvent.cpp Interactions/mitkInteractionEventConst.cpp Interactions/mitkInteractionPositionEvent.cpp Interactions/mitkInteractionKeyEvent.cpp Interactions/mitkMousePressEvent.cpp Interactions/mitkMouseMoveEvent.cpp Interactions/mitkMouseReleaseEvent.cpp Interactions/mitkMouseWheelEvent.cpp Interactions/mitkMouseDoubleClickEvent.cpp Interactions/mitkMouseModeSwitcher.cpp Interactions/mitkMouseMovePointSetInteractor.cpp Interactions/mitkMoveBaseDataInteractor.cpp Interactions/mitkNodeDepententPointSetInteractor.cpp Interactions/mitkPointSetDataInteractor.cpp Interactions/mitkPointSetInteractor.cpp Interactions/mitkPositionEvent.cpp Interactions/mitkPositionTracker.cpp Interactions/mitkStateMachineAction.cpp Interactions/mitkStateMachineCondition.cpp Interactions/mitkStateMachineState.cpp Interactions/mitkStateMachineTransition.cpp Interactions/mitkState.cpp Interactions/mitkStateMachineContainer.cpp Interactions/mitkStateEvent.cpp Interactions/mitkStateMachine.cpp Interactions/mitkStateMachineFactory.cpp Interactions/mitkTransition.cpp Interactions/mitkWheelEvent.cpp Interactions/mitkKeyEvent.cpp Interactions/mitkVtkEventAdapter.cpp Interactions/mitkVtkInteractorStyle.cxx Interactions/mitkCrosshairPositionEvent.cpp Interfaces/mitkInteractionEventObserver.cpp Interfaces/mitkIShaderRepository.cpp Interfaces/mitkIPropertyAliases.cpp Interfaces/mitkIPropertyDescriptions.cpp Interfaces/mitkIPropertyExtensions.cpp Interfaces/mitkIPropertyFilters.cpp IO/mitkBaseDataIOFactory.cpp IO/mitkCoreDataNodeReader.cpp IO/mitkDicomSeriesReader.cpp IO/mitkDicomSR_LoadDICOMScalar.cpp IO/mitkDicomSR_LoadDICOMScalar4D.cpp IO/mitkDicomSR_LoadDICOMRGBPixel.cpp IO/mitkDicomSR_LoadDICOMRGBPixel4D.cpp IO/mitkDicomSR_ImageBlockDescriptor.cpp IO/mitkDicomSR_GantryTiltInformation.cpp IO/mitkDicomSR_SliceGroupingResult.cpp IO/mitkFileReader.cpp IO/mitkFileSeriesReader.cpp IO/mitkFileWriter.cpp # IO/mitkIpPicGet.c IO/mitkImageGenerator.cpp IO/mitkImageWriter.cpp IO/mitkImageWriterFactory.cpp IO/mitkItkImageFileIOFactory.cpp IO/mitkItkImageFileReader.cpp IO/mitkItkLoggingAdapter.cpp IO/mitkItkPictureWrite.cpp IO/mitkIOUtil.cpp IO/mitkLookupTableProperty.cpp IO/mitkOperation.cpp # IO/mitkPicFileIOFactory.cpp # IO/mitkPicFileReader.cpp # IO/mitkPicFileWriter.cpp # IO/mitkPicHelper.cpp # IO/mitkPicVolumeTimeSeriesIOFactory.cpp # IO/mitkPicVolumeTimeSeriesReader.cpp IO/mitkPixelType.cpp IO/mitkPointSetIOFactory.cpp IO/mitkPointSetReader.cpp IO/mitkPointSetWriter.cpp IO/mitkPointSetWriterFactory.cpp IO/mitkRawImageFileReader.cpp IO/mitkStandardFileLocations.cpp IO/mitkSTLFileIOFactory.cpp IO/mitkSTLFileReader.cpp IO/mitkSurfaceVtkWriter.cpp IO/mitkSurfaceVtkWriterFactory.cpp IO/mitkVtkLoggingAdapter.cpp IO/mitkVtiFileIOFactory.cpp IO/mitkVtiFileReader.cpp IO/mitkVtkImageIOFactory.cpp IO/mitkVtkImageReader.cpp IO/mitkVtkSurfaceIOFactory.cpp IO/mitkVtkSurfaceReader.cpp IO/vtkPointSetXMLParser.cpp IO/mitkLog.cpp Rendering/mitkBaseRenderer.cpp Rendering/mitkVtkMapper.cpp Rendering/mitkRenderWindowFrame.cpp Rendering/mitkGeometry2DDataMapper2D.cpp Rendering/mitkGeometry2DDataVtkMapper3D.cpp Rendering/mitkGLMapper.cpp Rendering/mitkGradientBackground.cpp Rendering/mitkManufacturerLogo.cpp Rendering/mitkMapper.cpp Rendering/mitkPointSetGLMapper2D.cpp Rendering/mitkPointSetVtkMapper2D.cpp Rendering/mitkPointSetVtkMapper3D.cpp Rendering/mitkPolyDataGLMapper2D.cpp Rendering/mitkSurfaceGLMapper2D.cpp Rendering/mitkSurfaceVtkMapper3D.cpp Rendering/mitkVolumeDataVtkMapper3D.cpp Rendering/mitkVtkPropRenderer.cpp Rendering/mitkVtkWidgetRendering.cpp Rendering/vtkMitkRectangleProp.cpp Rendering/vtkMitkRenderProp.cpp Rendering/mitkVtkEventProvider.cpp Rendering/mitkRenderWindow.cpp Rendering/mitkRenderWindowBase.cpp - Rendering/mitkShaderRepository.cpp Rendering/mitkImageVtkMapper2D.cpp Rendering/vtkMitkThickSlicesFilter.cpp Rendering/vtkMitkLevelWindowFilter.cpp Rendering/vtkNeverTranslucentTexture.cpp Rendering/mitkOverlay.cpp Rendering/mitkVtkOverlay.cpp Rendering/mitkVtkOverlay2D.cpp Rendering/mitkVtkOverlay3D.cpp Rendering/mitkOverlayManager.cpp Rendering/mitkAbstractOverlayLayouter.cpp Rendering/mitkTextOverlay2D.cpp Rendering/mitkTextOverlay3D.cpp Rendering/mitkLabelOverlay3D.cpp Rendering/mitkOverlay2DLayouter.cpp Rendering/mitkScaleLegendOverlay Common/mitkException.cpp Common/mitkCommon.h Common/mitkCoreObjectFactoryBase.cpp Common/mitkCoreObjectFactory.cpp Common/mitkCoreServices.cpp ) set(RESOURCE_FILES Interactions/globalConfig.xml Interactions/DisplayInteraction.xml Interactions/DisplayConfig.xml Interactions/DisplayConfigPACS.xml Interactions/DisplayConfigPACSPan.xml Interactions/DisplayConfigPACSScroll.xml Interactions/DisplayConfigPACSZoom.xml Interactions/DisplayConfigPACSLevelWindow.xml Interactions/DisplayConfigMITK.xml Interactions/PointSet.xml Interactions/Legacy/StateMachine.xml Interactions/Legacy/DisplayConfigMITKTools.xml Interactions/PointSetConfig.xml -Shaders/mitkShaderLighting.xml - mitkLevelWindowPresets.xml ) diff --git a/Modules/CMakeLists.txt b/Modules/CMakeLists.txt index 4b9eb3613c..8f57adab94 100644 --- a/Modules/CMakeLists.txt +++ b/Modules/CMakeLists.txt @@ -1,77 +1,77 @@ set(LIBPOSTFIX "Ext") # Modules must be listed according to their dependencies set(module_dirs + Shaders MitkDataTypesExt MitkAlgorithmsExt MitkMapperExt MitkIOExt Qt4Qt5TestModule SceneSerializationBase PlanarFigure ImageExtraction ImageStatistics LegacyAdaptors IpPicSupport MitkExt SceneSerialization GraphAlgorithms ContourModel SurfaceInterpolation Segmentation PlanarFigureSegmentation OpenViewCore QmlMitk Qmitk QmitkExt SegmentationUI DiffusionImaging GPGPU IGTBase IGT CameraCalibration IGTUI RigidRegistration RigidRegistrationUI DeformableRegistration DeformableRegistrationUI OpenCL OpenCVVideoSupport Overlays InputDevices ToFHardware ToFProcessing ToFUI US ClippingTools USUI DicomUI Simulation - Shaders Remeshing Python ) if(MITK_ENABLE_PIC_READER) list(APPEND module_dirs IpPicSupportIO) endif() set(MITK_DEFAULT_SUBPROJECTS MITK-Modules) foreach(module_dir ${module_dirs}) add_subdirectory(${module_dir}) endforeach() if(MITK_PRIVATE_MODULES) file(GLOB all_subdirs RELATIVE ${MITK_PRIVATE_MODULES} ${MITK_PRIVATE_MODULES}/*) foreach(subdir ${all_subdirs}) string(FIND ${subdir} "." _result) if(_result EQUAL -1) if(EXISTS ${MITK_PRIVATE_MODULES}/${subdir}/CMakeLists.txt) message(STATUS "Found private module ${subdir}") add_subdirectory(${MITK_PRIVATE_MODULES}/${subdir} private_modules/${subdir}) endif() endif() endforeach() endif(MITK_PRIVATE_MODULES) diff --git a/Modules/Shaders/CMakeLists.txt b/Modules/Shaders/CMakeLists.txt index f31b48ef16..3713399f63 100644 --- a/Modules/Shaders/CMakeLists.txt +++ b/Modules/Shaders/CMakeLists.txt @@ -1,4 +1,4 @@ -MITK_CREATE_MODULE( Shaders +MITK_CREATE_MODULE(Shaders DEPENDS Mitk # WARNINGS_AS_ERRORS ) diff --git a/Core/Code/Resources/Shaders/mitkShaderLighting.xml b/Modules/Shaders/Resources/Shaders/mitkShaderLighting.xml similarity index 100% rename from Core/Code/Resources/Shaders/mitkShaderLighting.xml rename to Modules/Shaders/Resources/Shaders/mitkShaderLighting.xml diff --git a/Modules/Shaders/files.cmake b/Modules/Shaders/files.cmake index 3d0b5fe46e..15f3711584 100644 --- a/Modules/Shaders/files.cmake +++ b/Modules/Shaders/files.cmake @@ -1,13 +1,23 @@ SET(CPP_FILES vtkXMLMaterial.cxx vtkXMLMaterialParser.cxx vtkXMLMaterialReader.cxx vtkXMLShader.cxx + mitkShaderRepository.cpp + mitkShaderProperty.cpp + vtkPropertyXMLParser.cxx ) SET(H_FILES vtkXMLMaterial.h vtkXMLMaterialParser.h vtkXMLMaterialReader.h vtkXMLShader.h + mitkShaderRepository.h + mitkShaderProperty.h + vtkPropertyXMLParser.h +) + +set(RESOURCE_FILES + Shaders/mitkShaderLighting.xml ) diff --git a/Core/Code/DataManagement/mitkShaderProperty.cpp b/Modules/Shaders/mitkShaderProperty.cpp similarity index 100% rename from Core/Code/DataManagement/mitkShaderProperty.cpp rename to Modules/Shaders/mitkShaderProperty.cpp diff --git a/Core/Code/DataManagement/mitkShaderProperty.h b/Modules/Shaders/mitkShaderProperty.h similarity index 100% rename from Core/Code/DataManagement/mitkShaderProperty.h rename to Modules/Shaders/mitkShaderProperty.h diff --git a/Core/Code/Rendering/mitkShaderRepository.cpp b/Modules/Shaders/mitkShaderRepository.cpp similarity index 79% rename from Core/Code/Rendering/mitkShaderRepository.cpp rename to Modules/Shaders/mitkShaderRepository.cpp index fc219ba8f7..ae7ac6eb33 100644 --- a/Core/Code/Rendering/mitkShaderRepository.cpp +++ b/Modules/Shaders/mitkShaderRepository.cpp @@ -1,558 +1,456 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #define SR_INFO MITK_INFO("shader.repository") #define SR_WARN MITK_WARN("shader.repository") #define SR_ERROR MITK_ERROR("shader.repository") #include "mitkShaderRepository.h" #include "mitkShaderProperty.h" #include "mitkProperties.h" #include "mitkDataNode.h" #include #include -//#include -//#include +#include +#include +#include #include +#include #include #include int mitk::ShaderRepository::shaderId = 0; const bool mitk::ShaderRepository::debug = false; mitk::ShaderRepository::ShaderRepository() { LoadShaders(); } mitk::ShaderRepository::~ShaderRepository() { } void mitk::ShaderRepository::LoadShaders() { itk::Directory::Pointer dir = itk::Directory::New(); std::string dirPath = "./vtk_shader"; if( dir->Load( dirPath.c_str() ) ) { int n = dir->GetNumberOfFiles(); for(int r=0;rGetFile( r ); std::string extension = itksys::SystemTools::GetFilenameExtension(filename); if(extension.compare(".xml")==0) { Shader::Pointer element=Shader::New(); element->SetName(itksys::SystemTools::GetFilenameWithoutExtension(filename)); std::string filePath = dirPath + std::string("/") + element->GetName() + std::string(".xml"); SR_INFO(debug) << "found shader '" << element->GetName() << "'"; std::ifstream fileStream(filePath.c_str()); element->LoadProperties(fileStream); shaders.push_back(element); } } } } mitk::ShaderRepository::Shader::Pointer mitk::ShaderRepository::GetShaderImpl(const std::string &name) const { std::list::const_iterator i = shaders.begin(); while( i != shaders.end() ) { if( (*i)->GetName() == name) return (*i); i++; } return Shader::Pointer(); } int mitk::ShaderRepository::LoadShader(std::istream& stream, const std::string& filename) { Shader::Pointer element=Shader::New(); element->SetName(filename); element->SetId(shaderId++); element->LoadProperties(stream); shaders.push_back(element); SR_INFO(debug) << "found shader '" << element->GetName() << "'"; return element->GetId(); } bool mitk::ShaderRepository::UnloadShader(int id) { for (std::list::iterator i = shaders.begin(); i != shaders.end(); ++i) { if ((*i)->GetId() == id) { shaders.erase(i); return true; } } return false; } mitk::ShaderRepository::Shader::Shader() { } mitk::ShaderRepository::Shader::~Shader() { } void mitk::ShaderRepository::Shader::LoadProperties(vtkProperty* p) { // vtkXMLMaterial *m=p->GetMaterial(); // if (m == NULL) return; // Vertexshader uniforms // { // vtkXMLShader *s=m->GetVertexShader(); // if (s) // { // vtkXMLDataElement *x=s->GetRootElement(); // int n=x->GetNumberOfNestedElements(); // for(int r=0;rGetNestedElement(r); // if(!strcmp(y->GetName(),"ApplicationUniform")) // { // Uniform::Pointer element=Uniform::New(); // element->LoadFromXML(y); // uniforms.push_back(element); // } // } // } // } // Fragmentshader uniforms // { // vtkXMLShader *s=m->GetFragmentShader(); // if (s) // { // vtkXMLDataElement *x=s->GetRootElement(); // int n=x->GetNumberOfNestedElements(); // for(int r=0;rGetNestedElement(r); // if(!strcmp(y->GetName(),"ApplicationUniform")) // { // Uniform::Pointer element=Uniform::New(); // element->LoadFromXML(y); // uniforms.push_back(element); // } // } // } // } } -//---------------------------------------------------------------------------- -void vtkProperty::LoadMaterial(const char* name) -{ - this->SetMaterialName(0); - if( !name || strlen(name) == 0) - { - this->LoadMaterial(static_cast(0)); - return; - } - - // vtkXMLMaterial::CreateInstance using library/absolute path/repository - // in that order. - vtkXMLMaterial* material = vtkXMLMaterial::CreateInstance(name); - if (!material) - { - vtkErrorMacro("Failed to create Material : " << name); - return; - } - this->LoadMaterial(material); - material->Delete(); - return; -} - -//---------------------------------------------------------------------------- -void vtkProperty::LoadMaterialFromString(const char* materialxml) -{ - this->SetMaterialName(0); - if (!materialxml) - { - this->LoadMaterial(static_cast(0)); - return; - } - vtkXMLMaterialParser* parser = vtkXMLMaterialParser::New(); - vtkXMLMaterial* material = vtkXMLMaterial::New(); - parser->SetMaterial(material); - parser->Parse(materialxml); - parser->Delete(); - this->LoadMaterial(material); - material->Delete(); -} - -// ---------------------------------------------------------------------------- -// Description: -// Read this->Material from new style shaders. -// Default implementation is empty. -void vtkProperty::ReadFrameworkMaterial() -{ - // empty. See vtkOpenGLProperty. -} - -//---------------------------------------------------------------------------- -void vtkProperty::LoadMaterial(vtkXMLMaterial* material) -{ - this->SetMaterialName(0); - vtkSetObjectBodyMacro(Material, vtkXMLMaterial, material); - if (this->Material) - { - this->SetMaterialName(this->Material->GetRootElement()->GetAttribute("name")); - this->LoadProperty(); - this->LoadTextures(); - int lang = this->Material->GetShaderLanguage(); - int style = this->Material->GetShaderStyle(); - - if (style == 2) // TODO: use a constant instead of a literal - { - if (lang == vtkXMLShader::LANGUAGE_GLSL) - { - // ready-for-multipass - this->ReadFrameworkMaterial(); -// vtkShader2Collection *shaders=vtkShader2Collection::New(); -// this->SetShaderCollection(shaders); -// shaders->Delete(); - } - else - { - vtkErrorMacro(<<"style 2 is only supported with GLSL. Failed to setup the shader."); - this->SetShaderProgram(0); // failed to create shaders. - } - } - else - { - vtkShaderProgram* shader = vtkShaderProgram::CreateShaderProgram(lang); - if (shader) - { - this->SetShaderProgram(shader); - shader->Delete(); - this->ShaderProgram->SetMaterial(this->Material); - this->ShaderProgram->ReadMaterial(); - } - // Some materials may have no shaders and only set ivars for vtkProperty. - else if ((material->GetNumberOfVertexShaders() != 0) || - (material->GetNumberOfFragmentShaders() != 0)) - { - vtkErrorMacro("Failed to setup the shader."); - this->SetShaderProgram(0); // failed to create shaders. - } - } - } - else - { - this->SetShaderProgram(0); - } -} - void mitk::ShaderRepository::Shader::LoadProperties(std::istream& stream) { std::string content; content.reserve(2048); char buffer[2048]; while (stream.read(buffer, sizeof(buffer))) { content.append(buffer, sizeof(buffer)); } content.append(buffer, static_cast(stream.gcount())); if (content.empty()) return; this->SetMaterialXml(content); vtkProperty *p = vtkProperty::New(); // p->LoadMaterialFromString(content.c_str()); LoadProperties(p); p->Delete(); } mitk::ShaderRepository::Shader::Uniform::Uniform() { } mitk::ShaderRepository::Shader::Uniform::~Uniform() { } void mitk::ShaderRepository::Shader::Uniform::LoadFromXML(vtkXMLDataElement *y) { //MITK_INFO << "found uniform '" << y->GetAttribute("name") << "' type=" << y->GetAttribute("type");// << " default=" << y->GetAttribute("value"); name = y->GetAttribute("name"); const char *sType=y->GetAttribute("type"); if(!strcmp(sType,"float")) type=glsl_float; else if(!strcmp(sType,"vec2")) type=glsl_vec2; else if(!strcmp(sType,"vec3")) type=glsl_vec3; else if(!strcmp(sType,"vec4")) type=glsl_vec4; else if(!strcmp(sType,"int")) type=glsl_int; else if(!strcmp(sType,"ivec2")) type=glsl_ivec2; else if(!strcmp(sType,"ivec3")) type=glsl_ivec3; else if(!strcmp(sType,"ivec4")) type=glsl_ivec4; else { type=glsl_none; SR_WARN << "unknown type for uniform '" << name << "'" ; } defaultFloat[0]=defaultFloat[1]=defaultFloat[2]=defaultFloat[3]=0; /* const char *sDefault=y->GetAttribute("value"); switch(type) { case glsl_float: sscanf(sDefault,"%f",&defaultFloat[0]); break; case glsl_vec2: sscanf(sDefault,"%f %f",&defaultFloat[0],&defaultFloat[1]); break; case glsl_vec3: sscanf(sDefault,"%f %f %f",&defaultFloat[0],&defaultFloat[1],&defaultFloat[2]); break; case glsl_vec4: sscanf(sDefault,"%f %f %f %f",&defaultFloat[0],&defaultFloat[1],&defaultFloat[2],&defaultFloat[3]); break; } */ } void mitk::ShaderRepository::AddDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) const { node->AddProperty( "shader", mitk::ShaderProperty::New(), renderer, overwrite ); std::list::const_iterator i = shaders.begin(); while( i != shaders.end() ) { std::list *l = (*i)->GetUniforms(); std::string shaderName = (*i)->GetName(); std::list::const_iterator j = l->begin(); while( j != l->end() ) { std::string propertyName = "shader." + shaderName + "." + (*j)->name; switch( (*j)->type ) { case Shader::Uniform::glsl_float: node->AddProperty( propertyName.c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[0] ), renderer, overwrite ); break; case Shader::Uniform::glsl_vec2: node->AddProperty( (propertyName+".x").c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[0] ), renderer, overwrite ); node->AddProperty( (propertyName+".y").c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[1] ), renderer, overwrite ); break; case Shader::Uniform::glsl_vec3: node->AddProperty( (propertyName+".x").c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[0] ), renderer, overwrite ); node->AddProperty( (propertyName+".y").c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[1] ), renderer, overwrite ); node->AddProperty( (propertyName+".z").c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[2] ), renderer, overwrite ); break; case Shader::Uniform::glsl_vec4: node->AddProperty( (propertyName+".x").c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[0] ), renderer, overwrite ); node->AddProperty( (propertyName+".y").c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[1] ), renderer, overwrite ); node->AddProperty( (propertyName+".z").c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[2] ), renderer, overwrite ); node->AddProperty( (propertyName+".w").c_str(), mitk::FloatProperty::New( (*j)->defaultFloat[3] ), renderer, overwrite ); break; default: break; } j++; } i++; } } void mitk::ShaderRepository::ApplyProperties(mitk::DataNode* node, vtkActor *actor, mitk::BaseRenderer* renderer,itk::TimeStamp &MTime) const { bool setMTime = false; vtkProperty* property = actor->GetProperty(); unsigned long ts = MTime.GetMTime(); mitk::ShaderProperty *sep= dynamic_cast(node->GetProperty("shader",renderer)); if(!sep) { property->ShadingOff(); return; } std::string shader=sep->GetValueAsString(); // Need update pipeline mode if(sep->GetMTime() > ts) { if(shader.compare("fixed")==0) { //MITK_INFO << "disabling shader"; property->ShadingOff(); } else { Shader::Pointer s=GetShaderImpl(shader); if(s.IsNotNull()) { //MITK_INFO << "enabling shader"; property->ShadingOn(); // property->LoadMaterialFromString(s->GetMaterialXml().c_str()); } } setMTime = true; } if(shader.compare("fixed")!=0) { Shader::Pointer s=GetShaderImpl(shader); if(s.IsNull()) return; std::list::const_iterator j = s->uniforms.begin(); while( j != s->uniforms.end() ) { std::string propertyName = "shader." + s->GetName() + "." + (*j)->name; // MITK_INFO << "querying property: " << propertyName; // mitk::BaseProperty *p = node->GetProperty( propertyName.c_str(), renderer ); // if( p && p->GetMTime() > MTime.GetMTime() ) { float fval[4]; // MITK_INFO << "copying property " << propertyName << " ->->- " << (*j)->name << " type=" << (*j)->type ; switch( (*j)->type ) { case Shader::Uniform::glsl_float: node->GetFloatProperty( propertyName.c_str(), fval[0], renderer ); property->AddShaderVariable( (*j)->name.c_str(), 1 , fval ); break; case Shader::Uniform::glsl_vec2: node->GetFloatProperty( (propertyName+".x").c_str(), fval[0], renderer ); node->GetFloatProperty( (propertyName+".y").c_str(), fval[1], renderer ); property->AddShaderVariable( (*j)->name.c_str(), 2 , fval ); break; case Shader::Uniform::glsl_vec3: node->GetFloatProperty( (propertyName+".x").c_str(), fval[0], renderer ); node->GetFloatProperty( (propertyName+".y").c_str(), fval[1], renderer ); node->GetFloatProperty( (propertyName+".z").c_str(), fval[2], renderer ); property->AddShaderVariable( (*j)->name.c_str(), 3 , fval ); break; case Shader::Uniform::glsl_vec4: node->GetFloatProperty( (propertyName+".x").c_str(), fval[0], renderer ); node->GetFloatProperty( (propertyName+".y").c_str(), fval[1], renderer ); node->GetFloatProperty( (propertyName+".z").c_str(), fval[2], renderer ); node->GetFloatProperty( (propertyName+".w").c_str(), fval[3], renderer ); property->AddShaderVariable( (*j)->name.c_str(), 4 , fval ); break; default: break; } //setMTime=true; } j++; } } if(setMTime) MTime.Modified(); } std::list mitk::ShaderRepository::GetShaders() const { std::list result; for (std::list::const_iterator i = shaders.begin(); i != shaders.end(); ++i) { result.push_back(i->GetPointer()); } return result; } mitk::IShaderRepository::Shader::Pointer mitk::ShaderRepository::GetShader(const std::string& name) const { for (std::list::const_iterator i = shaders.begin(); i != shaders.end(); ++i) { if ((*i)->GetName() == name) return i->GetPointer(); } return IShaderRepository::Shader::Pointer(); } mitk::IShaderRepository::Shader::Pointer mitk::ShaderRepository::GetShader(int id) const { for (std::list::const_iterator i = shaders.begin(); i != shaders.end(); ++i) { if ((*i)->GetId() == id) return i->GetPointer(); } return IShaderRepository::Shader::Pointer(); } diff --git a/Core/Code/Rendering/mitkShaderRepository.h b/Modules/Shaders/mitkShaderRepository.h similarity index 99% rename from Core/Code/Rendering/mitkShaderRepository.h rename to Modules/Shaders/mitkShaderRepository.h index abe926baab..692e0f0c09 100644 --- a/Core/Code/Rendering/mitkShaderRepository.h +++ b/Modules/Shaders/mitkShaderRepository.h @@ -1,162 +1,163 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITKSHADERREPOSITORY_H_ #define _MITKSHADERREPOSITORY_H_ #include "mitkIShaderRepository.h" class vtkXMLDataElement; +class vtkXMLMaterial; class vtkProperty; namespace mitk { /** * \brief Management class for vtkShader XML descriptions. * * Looks for all XML shader files in a given directory and adds default properties * for each shader object (shader uniforms) to the specified mitk::DataNode. * * Additionally, it provides a utility function for applying properties for shaders * in mappers. */ class ShaderRepository : public IShaderRepository { protected: class Shader : public IShaderRepository::Shader { public: mitkClassMacro( Shader, itk::Object ) itkFactorylessNewMacro( Self ) class Uniform : public itk::Object { public: mitkClassMacro( Uniform, itk::Object ) itkFactorylessNewMacro( Self ) enum Type { glsl_none, glsl_float, glsl_vec2, glsl_vec3, glsl_vec4, glsl_int, glsl_ivec2, glsl_ivec3, glsl_ivec4 }; /** * Constructor */ Uniform(); /** * Destructor */ ~Uniform(); Type type; std::string name; int defaultInt[4]; float defaultFloat[4]; void LoadFromXML(vtkXMLDataElement *e); }; std::list uniforms; /** * Constructor */ Shader(); /** * Destructor */ ~Shader(); Uniform *GetUniform(char * /*id*/) { return 0; } std::list *GetUniforms() { return &uniforms; } private: friend class ShaderRepository; void LoadProperties(vtkProperty* prop); void LoadProperties(std::istream& stream); }; void LoadShaders(); Shader::Pointer GetShaderImpl(const std::string& name) const; private: std::list shaders; static int shaderId; static const bool debug; -public: + public: /** * Constructor */ ShaderRepository(); /** * Destructor */ ~ShaderRepository(); std::list GetShaders() const; IShaderRepository::Shader::Pointer GetShader(const std::string& name) const; IShaderRepository::Shader::Pointer GetShader(int id) const; /** \brief Adds all parsed shader uniforms to property list of the given DataNode; * used by mappers. */ void AddDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) const; /** \brief Applies shader and shader specific variables of the specified DataNode * to the VTK object by updating the shader variables of its vtkProperty. */ void ApplyProperties(mitk::DataNode* node, vtkActor *actor, mitk::BaseRenderer* renderer,itk::TimeStamp &MTime) const; int LoadShader(std::istream& stream, const std::string& name); bool UnloadShader(int id); }; } //end of namespace mitk #endif diff --git a/Modules/Shaders/vtkPropertyXMLParser.cxx b/Modules/Shaders/vtkPropertyXMLParser.cxx new file mode 100644 index 0000000000..8adc0bc70b --- /dev/null +++ b/Modules/Shaders/vtkPropertyXMLParser.cxx @@ -0,0 +1,1036 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: vtkPropertyXMLParser.cxx + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ +#include "vtkPropertyXMLParser.h" + +#include "vtkActor.h" +#include "vtkObjectFactory.h" +#include "vtkImageData.h" +#include "vtkImageReader2.h" +#include "vtkImageReader2Factory.h" +#include "vtkRenderer.h" +#include "vtkRenderWindow.h" +#include "vtkShaderProgram2.h" +#include "vtkSmartPointer.h" +#include "vtkStdString.h" +#include "vtkTexture.h" +#include "vtkXMLDataElement.h" +#include "vtkXMLMaterial.h" +#include "vtkXMLMaterialParser.h" +#include "vtkXMLShader.h" + +#include +#include + +#include +#include + +class vtkPropertyInternals +{ +public: + // key==texture unit, value==texture + typedef std::map > MapOfTextures; + MapOfTextures Textures; + + // key==texture name, value==texture-unit. + typedef std::map MapOfTextureNames; + MapOfTextureNames TextureNames; +}; + +vtkCxxSetObjectMacro(vtkPropertyXMLParser, ShaderProgram, vtkShaderProgram2); +//---------------------------------------------------------------------------- +// Return NULL if no override is supplied. +vtkAbstractObjectFactoryNewMacro(vtkPropertyXMLParser) +//---------------------------------------------------------------------------- + +// Construct object with object color, ambient color, diffuse color, + +enum IVarEnum { + IVarNone = 0, + IVarColor, + IVarAmbientColor, + IVarDiffuseColor, + IVarSpecularColor, + IVarEdgeColor, + IVarAmbient, + IVarDiffuse, + IVarSpecular, + IVarSpecularPower, + IVarOpacity, + + IVarPointSize, + IVarLineWidth, + + IVarLineStipplePattern, + IVarLineStippleRepeatFactor, + IVarInterpolation, + IVarRepresentation, + IVarEdgeVisibility, + IVarBackfaceCulling, + IVarFrontfaceCulling +}; + +static IVarEnum XMLMemberToIvar(const char* name) +{ + if (!strcmp(name, "Color")) + { + return IVarColor; + } + if (!strcmp(name, "AmbientColor")) + { + return IVarAmbientColor; + } + if (!strcmp(name, "DiffuseColor")) + { + return IVarDiffuseColor; + } + if (!strcmp(name, "SpecularColor")) + { + return IVarSpecularColor; + } + if (!strcmp(name, "EdgeColor")) + { + return IVarEdgeColor; + } + if (!strcmp(name, "Ambient")) + { + return IVarAmbient; + } + if (!strcmp(name, "Diffuse")) + { + return IVarDiffuse; + } + if (!strcmp(name, "Specular")) + { + return IVarSpecular; + } + if (!strcmp(name, "SpecularPower")) + { + return IVarSpecularPower; + } + if (!strcmp(name, "Opacity")) + { + return IVarOpacity; + } + if (!strcmp(name, "PointSize")) + { + return IVarPointSize; + } + if (!strcmp(name, "LineWidth")) + { + return IVarLineWidth; + } + if (!strcmp(name, "LineStipplePattern")) + { + return IVarLineStipplePattern; + } + if (!strcmp(name, "LineStippleRepeatFactor")) + { + return IVarLineStippleRepeatFactor; + } + if (!strcmp(name, "Interpolation")) + { + return IVarInterpolation; + } + if (!strcmp(name, "Representation")) + { + return IVarRepresentation; + } + if (!strcmp(name, "EdgeVisibility")) + { + return IVarEdgeVisibility; + } + if (!strcmp(name, "BackfaceCulling")) + { + return IVarBackfaceCulling; + } + if (!strcmp(name, "FrontfaceCulling")) + { + return IVarFrontfaceCulling; + } + return IVarNone; +} + + +// specular color, and edge color white; ambient coefficient=0; diffuse +// coefficient=0; specular coefficient=0; specular power=1; Gouraud shading; +// and surface representation. Backface and frontface culling are off. +vtkPropertyXMLParser::vtkPropertyXMLParser() +{ + // Really should initialize all colors including Color[3] + this->Color[0] = 1; + this->Color[1] = 1; + this->Color[2] = 1; + + this->AmbientColor[0] = 1; + this->AmbientColor[1] = 1; + this->AmbientColor[2] = 1; + + this->DiffuseColor[0] = 1; + this->DiffuseColor[1] = 1; + this->DiffuseColor[2] = 1; + + this->SpecularColor[0] = 1; + this->SpecularColor[1] = 1; + this->SpecularColor[2] = 1; + + this->EdgeColor[0] = 0; + this->EdgeColor[1] = 0; + this->EdgeColor[2] = 0; + + this->Ambient = 0.0; + this->Diffuse = 1.0; + this->Specular = 0.0; + this->SpecularPower = 1.0; + this->Opacity = 1.0; + this->Interpolation = VTK_GOURAUD; + this->Representation = VTK_SURFACE; + this->EdgeVisibility = 0; + this->BackfaceCulling = 0; + this->FrontfaceCulling = 0; + this->PointSize = 1.0; + this->LineWidth = 1.0; + this->LineStipplePattern = 0xFFFF; + this->LineStippleRepeatFactor = 1; + this->Lighting = true; + + this->Shading = 0; + this->ShaderProgram = 0; + this->Material = 0; + this->MaterialName = 0; + this->Internals = new vtkPropertyInternals; +} + +//---------------------------------------------------------------------------- +vtkPropertyXMLParser::~vtkPropertyXMLParser() +{ + if (this->Material) + { + this->Material->UnRegister(this); + this->Material = 0; + } + this->SetShaderProgram(0); + this->SetMaterialName(0); + delete this->Internals; +} + +//---------------------------------------------------------------------------- +// Assign one property to another. +void vtkPropertyXMLParser::DeepCopy(vtkPropertyXMLParser *p) +{ + if (p != NULL) + { + this->SetColor(p->GetColor()); + this->SetAmbientColor(p->GetAmbientColor()); + this->SetDiffuseColor(p->GetDiffuseColor()); + this->SetSpecularColor(p->GetSpecularColor()); + this->SetEdgeColor(p->GetEdgeColor()); + this->SetAmbient(p->GetAmbient()); + this->SetDiffuse(p->GetDiffuse()); + this->SetSpecular(p->GetSpecular()); + this->SetSpecularPower(p->GetSpecularPower()); + this->SetOpacity(p->GetOpacity()); + this->SetInterpolation(p->GetInterpolation()); + this->SetRepresentation(p->GetRepresentation()); + this->SetEdgeVisibility(p->GetEdgeVisibility()); + this->SetBackfaceCulling(p->GetBackfaceCulling()); + this->SetFrontfaceCulling(p->GetFrontfaceCulling()); + this->SetPointSize(p->GetPointSize()); + this->SetLineWidth(p->GetLineWidth()); + this->SetLineStipplePattern(p->GetLineStipplePattern()); + this->SetLineStippleRepeatFactor(p->GetLineStippleRepeatFactor()); + this->SetShading(p->GetShading()); + this->LoadMaterial(p->GetMaterial()); + + this->RemoveAllTextures(); + vtkPropertyInternals::MapOfTextures::iterator iter = + p->Internals->Textures.begin(); + for (;iter != p->Internals->Textures.end(); ++iter) + { + this->Internals->Textures[iter->first] = iter->second; + } + // TODO: need to pass shader variables. + } +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::SetColor(double r, double g, double b) +{ + // Really should set the placeholder Color[3] variable + this->Color[0] = r; + this->Color[1] = g; + this->Color[2] = b; + + // Use Set macros to insure proper modified time behavior + this->SetAmbientColor(this->Color); + this->SetDiffuseColor(this->Color); + this->SetSpecularColor(this->Color); +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::SetColor(double a[3]) +{ + this->SetColor(a[0], a[1], a[2]); +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::ComputeCompositeColor(double result[3], + double ambient, const double ambient_color[3], + double diffuse, const double diffuse_color[3], + double specular, const double specular_color[3]) +{ + double norm = 0.0; + if ((ambient + diffuse + specular)>0) + { + norm = 1.0 / (ambient + diffuse + specular); + } + + for (int i = 0; i < 3; i ++) + { + result[i] = ( ambient * ambient_color[i] + + diffuse * diffuse_color[i] + + specular * specular_color[i] ) * norm; + } +} + +//---------------------------------------------------------------------------- +// Return composite color of object (ambient + diffuse + specular). Return value +// is a pointer to rgb values. +double *vtkPropertyXMLParser::GetColor() +{ + vtkPropertyXMLParser::ComputeCompositeColor(this->Color, + this->Ambient, this->AmbientColor, + this->Diffuse, this->DiffuseColor, + this->Specular, this->SpecularColor); + return this->Color; +} + +//---------------------------------------------------------------------------- +// Copy composite color of object (ambient + diffuse + specular) into array +// provided. +void vtkPropertyXMLParser::GetColor(double rgb[3]) +{ + this->GetColor(); + rgb[0] = this->Color[0]; + rgb[1] = this->Color[1]; + rgb[2] = this->Color[2]; +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::GetColor(double &r, double &g, double &b) +{ + this->GetColor(); + r = this->Color[0]; + g = this->Color[1]; + b = this->Color[2]; +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::SetTexture(const char* name, vtkTexture* tex) +{ + vtkPropertyInternals::MapOfTextureNames::iterator iter = + this->Internals->TextureNames.find(vtkStdString(name)); + if (iter != this->Internals->TextureNames.end()) + { + vtkWarningMacro("Texture with name " << name + << " exists. It will be replaced."); + } + + // Locate a free texture unit. + int texture_unit = -1; + for (int cc=0; ; cc++) + { + if (this->Internals->Textures.find(cc) == this->Internals->Textures.end()) + { + texture_unit = cc; + break; + } + } + + this->Internals->TextureNames[name] = texture_unit; + this->SetTexture(texture_unit, tex); +} + +//---------------------------------------------------------------------------- +vtkTexture* vtkPropertyXMLParser::GetTexture(const char* name) +{ + vtkPropertyInternals::MapOfTextureNames::iterator iter = + this->Internals->TextureNames.find(vtkStdString(name)); + if (iter == this->Internals->TextureNames.end()) + { + vtkErrorMacro("No texture with name " << name << " exists."); + return NULL; + } + + return this->GetTexture(iter->second); +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::SetTexture(int unit, vtkTexture* tex) +{ + vtkPropertyInternals::MapOfTextures::iterator iter = + this->Internals->Textures.find(unit); + if (iter != this->Internals->Textures.end()) + { + vtkWarningMacro("Replacing texture previously assigned to unit " << unit); + } + this->Internals->Textures[unit] = tex; +} + +//---------------------------------------------------------------------------- +vtkTexture* vtkPropertyXMLParser::GetTexture(int unit) +{ + vtkPropertyInternals::MapOfTextures::iterator iter = + this->Internals->Textures.find(unit); + if (iter != this->Internals->Textures.end()) + { + return iter->second.GetPointer(); + } + vtkErrorMacro("No texture assigned to texture unit " << unit << " exists."); + return NULL; +} + +//---------------------------------------------------------------------------- +int vtkPropertyXMLParser::GetNumberOfTextures() +{ + return static_cast(this->Internals->Textures.size()); +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::RemoveTexture(const char* name) +{ + vtkPropertyInternals::MapOfTextureNames::iterator iter = + this->Internals->TextureNames.find(vtkStdString(name)); + if (iter != this->Internals->TextureNames.end()) + { + this->RemoveTexture(iter->second); + this->Internals->TextureNames.erase(iter); + } +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::RemoveTexture(int unit) +{ + vtkPropertyInternals::MapOfTextures::iterator iter = + this->Internals->Textures.find(unit); + if (iter != this->Internals->Textures.end()) + { + this->Internals->Textures.erase(unit); + } +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::RemoveAllTextures() +{ + this->Internals->TextureNames.clear(); + this->Internals->Textures.clear(); +} + +//---------------------------------------------------------------------------- +vtkTexture* vtkPropertyXMLParser::GetTextureAtIndex(int index) +{ + vtkPropertyInternals::MapOfTextures::iterator iter = + this->Internals->Textures.begin(); + for (int id = 0; iter != this->Internals->Textures.end(); ++iter, ++id) + { + if (id == index) + { + return iter->second.GetPointer(); + } + } + + vtkErrorMacro("No texture at index " << index ); + return 0; +} + +//---------------------------------------------------------------------------- +int vtkPropertyXMLParser::GetTextureUnitAtIndex(int index) +{ + vtkPropertyInternals::MapOfTextures::iterator iter = + this->Internals->Textures.begin(); + for (int id = 0; iter != this->Internals->Textures.end(); ++iter, ++id) + { + if (id == index) + { + return iter->first; + } + } + + vtkErrorMacro("No texture at index " << index ); + return -1; +} + +//---------------------------------------------------------------------------- +int vtkPropertyXMLParser::GetTextureUnit(const char* name) +{ + vtkPropertyInternals::MapOfTextureNames::iterator iter = + this->Internals->TextureNames.find(name); + if (iter != this->Internals->TextureNames.end()) + { + return iter->second; + } + + vtkErrorMacro("No texture with name " << name); + return -1; +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::LoadMaterial(const char* name) +{ + this->SetMaterialName(0); + if( !name || strlen(name) == 0) + { + this->LoadMaterial(static_cast(0)); + return; + } + + // vtkXMLMaterial::CreateInstance using library/absolute path/repository + // in that order. + vtkXMLMaterial* material = vtkXMLMaterial::CreateInstance(name); + if (!material) + { + vtkErrorMacro("Failed to create Material : " << name); + return; + } + this->LoadMaterial(material); + material->Delete(); + return; +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::LoadMaterialFromString(const char* materialxml) +{ + this->SetMaterialName(0); + if (!materialxml) + { + this->LoadMaterial(static_cast(0)); + return; + } + vtkXMLMaterialParser* parser = vtkXMLMaterialParser::New(); + vtkXMLMaterial* material = vtkXMLMaterial::New(); + parser->SetMaterial(material); + parser->Parse(materialxml); + parser->Delete(); + this->LoadMaterial(material); + material->Delete(); +} + +// ---------------------------------------------------------------------------- +// Description: +// Read this->Material from new style shaders. +// Default implementation is empty. +void vtkPropertyXMLParser::ReadFrameworkMaterial() +{ + // empty. See vtkOpenGLProperty. +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::LoadMaterial(vtkXMLMaterial* material) +{ + this->SetMaterialName(0); + vtkSetObjectBodyMacro(Material, vtkXMLMaterial, material); + if (this->Material) + { + this->SetMaterialName(this->Material->GetRootElement()->GetAttribute("name")); + this->LoadProperty(); + this->LoadTextures(); + int style = this->Material->GetShaderStyle(); + + if (style == 2) // TODO: use a constant instead of a literal + { + // ready-for-multipass + this->ReadFrameworkMaterial(); +// vtkShader2Collection *shaders=vtkShader2Collection::New(); +// this->SetShaderCollection(shaders); +// shaders->Delete(); + } + else + { +/* vtkShaderProgram2* shader = vtkShaderProgram2::CreateShaderProgram(lang); TODO create shader??? + if (shader) + { + this->SetShaderProgram(shader); + shader->Delete(); + this->ShaderProgram->SetMaterial(this->Material); + this->ShaderProgram->ReadMaterial(); + } + // Some materials may have no shaders and only set ivars for vtkPropertyXMLParser. + else if ((material->GetNumberOfVertexShaders() != 0) || + (material->GetNumberOfFragmentShaders() != 0)) + { + vtkErrorMacro("Failed to setup the shader."); + this->SetShaderProgram(0); // failed to create shaders. + }*/ + } + } + else + { + this->SetShaderProgram(0); + } +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::LoadProperty() +{ + vtkXMLDataElement* elem = this->Material->GetProperty(); + if (elem == NULL ) + { + return; + } + + int numNested = elem->GetNumberOfNestedElements(); + + // Each element is a child node of + for (int iElem = 0; iElem < numNested; iElem++) + { + vtkXMLDataElement* currElement = elem->GetNestedElement(iElem); + const char* tagname = currElement->GetName(); + + if (!strcmp(tagname, "Member")) + { + this->LoadMember(currElement); + } + else + { + vtkErrorMacro("Unknown tag name '" << tagname << "'"); + } + } +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::LoadTextures() +{ + int numTextures = this->Material->GetNumberOfTextures(); + for (int i = 0; i < numTextures; i++) + { + this->LoadTexture(this->Material->GetTexture(i)); + } +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::LoadMember(vtkXMLDataElement* elem) +{ + const char* name = elem->GetAttribute("name"); + if (!name) + { + vtkErrorMacro("Element missing required attribute 'name'"); + return; + } + + if (!elem->GetAttribute("value")) + { + vtkErrorMacro("Element with name=" << name << " missing required attribute " + "'value'"); + return; + } + int number_of_elements; + int* pint = 0; + double* pdouble = 0; + float* pfloat = 0; + int success = 0; + + IVarEnum member = XMLMemberToIvar( name ); + + // Sort to find the correct number of ivar values + if ( member == IVarColor || + member == IVarAmbientColor|| + member == IVarDiffuseColor|| + member == IVarSpecularColor|| + member == IVarEdgeColor ) + { + number_of_elements = 3; + } + else if ( member == IVarAmbient || + member == IVarDiffuse || + member == IVarSpecular || + member == IVarSpecularPower || + member == IVarSpecularColor|| + member == IVarOpacity || + member == IVarPointSize || + member == IVarLineWidth || + member == IVarLineStipplePattern || + member == IVarLineStippleRepeatFactor || + member == IVarInterpolation || + member == IVarRepresentation || + member == IVarEdgeVisibility || + member == IVarBackfaceCulling || + member == IVarFrontfaceCulling ) + { + number_of_elements = 1; + } + else + { + vtkErrorMacro("Invalid name='" << name); + return; + } + + + + if ( (member == IVarColor) || + (member == IVarAmbientColor) || + (member == IVarDiffuseColor) || + (member == IVarSpecularColor) || + (member == IVarEdgeColor) || + (member == IVarAmbient) || + (member == IVarDiffuse) || + (member == IVarSpecular) || + (member == IVarSpecularPower) || + (member == IVarOpacity) ) + { + pdouble = new double[number_of_elements]; + success = elem->GetVectorAttribute("value", number_of_elements, pdouble); + } + else if( (member == IVarPointSize) || + (member == IVarLineWidth) ) + { + pfloat = new float[number_of_elements]; + success = elem->GetVectorAttribute("value", number_of_elements, pfloat); + } + else if ( (member == IVarLineStipplePattern) || + (member == IVarLineStippleRepeatFactor) || + (member == IVarInterpolation) || + (member == IVarRepresentation) || + (member == IVarEdgeVisibility) || + (member == IVarBackfaceCulling) || + (member == IVarFrontfaceCulling) ) + { + pint = new int[number_of_elements]; + success = elem->GetVectorAttribute( "value", number_of_elements, pint); + } + else + { + vtkErrorMacro("Invalid name='" << name); + return; + } + + if (!success) + { + vtkErrorMacro("Error reading 'value' for name=" << name); + delete []pdouble; + delete []pfloat; + delete []pint; + return; + } + + if (pdouble) + { + if (member == IVarColor) + { + this->SetColor(pdouble); + } + else if (member == IVarAmbientColor) + { + this->SetAmbientColor(pdouble); + } + else if (member == IVarDiffuseColor) + { + this->SetDiffuseColor(pdouble); + } + else if (member == IVarSpecularColor) + { + this->SetSpecularColor(pdouble); + } + else if (member == IVarEdgeColor) + { + this->SetEdgeColor(pdouble); + } + else if (member == IVarAmbient) + { + this->SetAmbient(*pdouble); + } + else if (member == IVarDiffuse) + { + this->SetDiffuse(*pdouble); + } + else if (member == IVarSpecular) + { + this->SetSpecular(*pdouble); + } + else if (member == IVarSpecularPower) + { + this->SetSpecularPower(*pdouble); + } + else if (member == IVarOpacity) + { + this->SetOpacity(*pdouble); + } + } + else if (pfloat) + { + if (member == IVarPointSize) + { + this->SetPointSize(*pfloat); + } + else if (member == IVarLineWidth) + { + this->SetLineWidth(*pfloat); + } + } + else if (pint) + { + if (member == IVarLineStipplePattern) + { + this->SetLineStipplePattern(*pint); + } + else if (member == IVarLineStippleRepeatFactor) + { + this->SetLineStippleRepeatFactor(*pint); + } + else if (member == IVarInterpolation) + { + this->SetInterpolation(*pint); + } + else if (member == IVarRepresentation) + { + this->SetRepresentation(*pint); + } + else if (member == IVarEdgeVisibility) + { + this->SetEdgeVisibility(*pint); + } + else if (member == IVarBackfaceCulling) + { + this->SetBackfaceCulling(*pint); + } + else if (member == IVarFrontfaceCulling) + { + this->SetFrontfaceCulling(*pint); + } + } + + delete [] pdouble; + delete [] pfloat; + delete [] pint; +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::LoadTexture(vtkXMLDataElement* elem ) +{ + const char* name = elem->GetAttribute("name"); + if (!name) + { + vtkErrorMacro("Missing required attribute 'name'"); + return; + } + + const char* type = elem->GetAttribute("type"); + if (!type) + { + vtkErrorMacro("Missing required attribute 'type' " + "for element with name=" << name); + return; + } + + const char* location = elem->GetAttribute("location"); + if (!location) + { + vtkErrorMacro("Missing required attribute 'location'" + "for element with name=" << name); + return; + } + + char* filename = vtkXMLShader::LocateFile(location); + + vtkImageReader2* reader = + vtkImageReader2Factory::CreateImageReader2(filename); + + if (!reader) + { + vtkErrorMacro("Invalid format for element with name=" + << name); + return; + } + + if (filename) + { + reader->SetFileName(filename); + vtkTexture* t = vtkTexture::New(); + t->SetInputConnection(reader->GetOutputPort()); + t->InterpolateOn(); + this->SetTexture(name, t); + t->Delete(); + } + else + { + vtkErrorMacro("Failed to locate texture file " << location); + } + + reader->Delete(); + delete [] filename; +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::LoadPerlineNoise(vtkXMLDataElement* ) +{ + vtkWarningMacro("Perlin Noise support not complete yet!"); +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::Render(vtkActor* actor, vtkRenderer* renderer) +{ + // subclass would have renderer the property already. + // this class, just handles the shading. + + if (renderer->GetSelector()) + { + // nothing to do when rendering for hardware selection. + return; + } + + if (this->ShaderProgram && this->GetShading()) + { + vtkDebugMacro("Attempting to use Shaders"); + +// this->ShaderProgram->Render(actor, renderer); + } +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::PostRender(vtkActor* actor, vtkRenderer* renderer) +{ + if (renderer->GetSelector()) + { + // nothing to do when rendering for hardware selection. + return; + } + + if (this->ShaderProgram && this->Shading) + { +// this->ShaderProgram->PostRender(actor, renderer); + } +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::AddShaderVariable(const char* name, int numVars, int* x) +{ + if (!this->ShaderProgram) + { + return; + } +// this->ShaderProgram->AddShaderVariable(name, numVars, x); +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::AddShaderVariable(const char* name, int numVars, float* x) +{ + if (!this->ShaderProgram) + { + return; + } +// this->ShaderProgram->AddShaderVariable(name, numVars, x); +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::AddShaderVariable(const char* name, int numVars, double* x) +{ + if (!this->ShaderProgram) + { + return; + } +// this->ShaderProgram->AddShaderVariable(name, numVars, x); +} + +//----------------------------------------------------------------------------- +void vtkPropertyXMLParser::ReleaseGraphicsResources(vtkWindow *win) +{ + if (this->ShaderProgram) + { +// this->ShaderProgram->ReleaseGraphicsResources(win); + } + + // vtkOpenGLRenderer releases texture resources, so we don't need to release + // them here. +} + +//---------------------------------------------------------------------------- +void vtkPropertyXMLParser::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); + + os << indent << "Ambient: " << this->Ambient << "\n"; + os << indent << "Ambient Color: (" << this->AmbientColor[0] << ", " + << this->AmbientColor[1] << ", " << this->AmbientColor[2] << ")\n"; + os << indent << "Diffuse: " << this->Diffuse << "\n"; + os << indent << "Diffuse Color: (" << this->DiffuseColor[0] << ", " + << this->DiffuseColor[1] << ", " << this->DiffuseColor[2] << ")\n"; + os << indent << "Edge Color: (" << this->EdgeColor[0] << ", " + << this->EdgeColor[1] << ", " << this->EdgeColor[2] << ")\n"; + os << indent << "Edge Visibility: " + << (this->EdgeVisibility ? "On\n" : "Off\n"); + os << indent << "Interpolation: "; + switch (this->Interpolation) + { + case VTK_FLAT: os << "VTK_FLAT\n"; break; + case VTK_GOURAUD: os << "VTK_GOURAUD\n"; break; + case VTK_PHONG: os << "VTK_PHONG\n"; break; + default: os << "unknown\n"; + } + os << indent << "Opacity: " << this->Opacity << "\n"; + os << indent << "Representation: "; + switch (this->Representation) + { + case VTK_POINTS: os << "VTK_POINTS\n"; break; + case VTK_WIREFRAME: os << "VTK_WIREFRAME\n"; break; + case VTK_SURFACE: os << "VTK_SURFACE\n"; break; + default: os << "unknown\n"; + } + os << indent << "Specular: " << this->Specular << "\n"; + os << indent << "Specular Color: (" << this->SpecularColor[0] << ", " + << this->SpecularColor[1] << ", " << this->SpecularColor[2] << ")\n"; + os << indent << "Specular Power: " << this->SpecularPower << "\n"; + os << indent << "Backface Culling: " + << (this->BackfaceCulling ? "On\n" : "Off\n"); + os << indent << "Frontface Culling: " + << (this->FrontfaceCulling ? "On\n" : "Off\n"); + os << indent << "Point size: " << this->PointSize << "\n"; + os << indent << "Line width: " << this->LineWidth << "\n"; + os << indent << "Line stipple pattern: " << this->LineStipplePattern << "\n"; + os << indent << "Line stipple repeat factor: " << this->LineStippleRepeatFactor << "\n"; + os << indent << "Lighting: "; + if(this->Lighting) + { + os << "On" << endl; + } + else + { + os << "Off" << endl; + } + + os << indent << "Shading: " + << (this->Shading? "On" : "Off") << endl; + + os << indent << "Material: " ; + if (this->Material) + { + os << endl; + this->Material->PrintSelf(os, indent.GetNextIndent()); + } + else + { + os << "(none)" << endl; + } + os << indent << "MaterialName: " << + (this->MaterialName? this->MaterialName:"(none)") << endl; + + os << indent << "ShaderProgram: "; + if (this->ShaderProgram) + { + os << endl; + this->ShaderProgram->PrintSelf(os, indent.GetNextIndent()); + } + else + { + os << "(none)" << endl; + } +} diff --git a/Modules/Shaders/vtkPropertyXMLParser.h b/Modules/Shaders/vtkPropertyXMLParser.h new file mode 100644 index 0000000000..c0fe433987 --- /dev/null +++ b/Modules/Shaders/vtkPropertyXMLParser.h @@ -0,0 +1,487 @@ +/*========================================================================= + + Program: Visualization Toolkit + Module: vtkPropertyXMLParser.h + + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ +// .NAME vtkPropertyXMLParser - represent surface properties of a geometric object +// .SECTION Description +// vtkPropertyXMLParser is an object that represents lighting and other surface +// properties of a geometric object. The primary properties that can be +// set are colors (overall, ambient, diffuse, specular, and edge color); +// specular power; opacity of the object; the representation of the +// object (points, wireframe, or surface); and the shading method to be +// used (flat, Gouraud, and Phong). Also, some special graphics features +// like backface properties can be set and manipulated with this object. + +// .SECTION See Also +// vtkActor vtkPropertyXMLParserDevice + +#ifndef __vtkPropertyXMLParser_h +#define __vtkPropertyXMLParser_h + +#include "vtkRenderingCoreModule.h" // For export macro +#include "vtkObject.h" + +// shading models +#define VTK_FLAT 0 +#define VTK_GOURAUD 1 +#define VTK_PHONG 2 + +// representation models +#define VTK_POINTS 0 +#define VTK_WIREFRAME 1 +#define VTK_SURFACE 2 + +class vtkActor; +class vtkRenderer; +class vtkShaderProgram2; +class vtkShaderDeviceAdapter2; +class vtkTexture; +class vtkWindow; +class vtkXMLDataElement; +class vtkXMLMaterial; + +class vtkPropertyInternals; + +class VTKRENDERINGCORE_EXPORT vtkPropertyXMLParser : public vtkObject +{ +public: + vtkTypeMacro(vtkPropertyXMLParser,vtkObject); + void PrintSelf(ostream& os, vtkIndent indent); + + // Description: + // Construct object with object color, ambient color, diffuse color, + // specular color, and edge color white; ambient coefficient=0; diffuse + // coefficient=0; specular coefficient=0; specular power=1; Gouraud shading; + // and surface representation. Backface and frontface culling are off. + static vtkPropertyXMLParser *New(); + + // Description: + // Assign one property to another. + void DeepCopy(vtkPropertyXMLParser *p); + + // Description: + // This method causes the property to set up whatever is required for + // its instance variables. This is actually handled by a subclass of + // vtkPropertyXMLParser, which is created automatically. This + // method includes the invoking actor as an argument which can + // be used by property devices that require the actor. + virtual void Render(vtkActor *, vtkRenderer *); + + // Description: + // This method renders the property as a backface property. TwoSidedLighting + // must be turned off to see any backface properties. Note that only + // colors and opacity are used for backface properties. Other properties + // such as Representation, Culling are specified by the Property. + virtual void BackfaceRender(vtkActor *, vtkRenderer *) {} + + //BTX + // Description: + // This method is called after the actor has been rendered. + // Don't call this directly. This method cleans up + // any shaders allocated. + virtual void PostRender(vtkActor*, vtkRenderer*); + //ETX + + // Description: + // Set/Get lighting flag for an object. Initial value is true. + vtkGetMacro(Lighting, bool); + vtkSetMacro(Lighting, bool); + vtkBooleanMacro(Lighting, bool); + + // Description: + // Set the shading interpolation method for an object. + vtkSetClampMacro(Interpolation, int, VTK_FLAT, VTK_PHONG); + vtkGetMacro(Interpolation,int); + void SetInterpolationToFlat() + { this->SetInterpolation(VTK_FLAT); } + void SetInterpolationToGouraud() + { this->SetInterpolation(VTK_GOURAUD); } + void SetInterpolationToPhong() + { this->SetInterpolation(VTK_PHONG); } + const char *GetInterpolationAsString(); + + // Description: + // Control the surface geometry representation for the object. + vtkSetClampMacro(Representation,int, VTK_POINTS, VTK_SURFACE); + vtkGetMacro(Representation,int); + void SetRepresentationToPoints() + { this->SetRepresentation(VTK_POINTS); } + void SetRepresentationToWireframe() + { this->SetRepresentation(VTK_WIREFRAME); } + void SetRepresentationToSurface() + { this->SetRepresentation(VTK_SURFACE); } + const char *GetRepresentationAsString(); + + // Description: + // Set the color of the object. Has the side effect of setting the + // ambient diffuse and specular colors as well. This is basically + // a quick overall color setting method. + virtual void SetColor(double r, double g, double b); + virtual void SetColor(double a[3]); + double *GetColor(); + void GetColor(double rgb[3]); + void GetColor(double &r, double &g, double &b); + + // Description: + // Set/Get the ambient lighting coefficient. + vtkSetClampMacro(Ambient, double, 0.0, 1.0); + vtkGetMacro(Ambient, double); + + // Description: + // Set/Get the diffuse lighting coefficient. + vtkSetClampMacro(Diffuse, double, 0.0, 1.0); + vtkGetMacro(Diffuse, double); + + // Description: + // Set/Get the specular lighting coefficient. + vtkSetClampMacro(Specular, double, 0.0, 1.0); + vtkGetMacro(Specular, double); + + // Description: + // Set/Get the specular power. + vtkSetClampMacro(SpecularPower, double, 0.0, 128.0); + vtkGetMacro(SpecularPower, double); + + // Description: + // Set/Get the object's opacity. 1.0 is totally opaque and 0.0 is completely + // transparent. + vtkSetClampMacro(Opacity, double, 0.0, 1.0); + vtkGetMacro(Opacity, double); + + // Description: + // Set/Get the ambient surface color. Not all renderers support separate + // ambient and diffuse colors. From a physical standpoint it really + // doesn't make too much sense to have both. For the rendering + // libraries that don't support both, the diffuse color is used. + vtkSetVector3Macro(AmbientColor, double); + vtkGetVector3Macro(AmbientColor, double); + + // Description: + // Set/Get the diffuse surface color. + vtkSetVector3Macro(DiffuseColor, double); + vtkGetVector3Macro(DiffuseColor, double); + + // Description: + // Set/Get the specular surface color. + vtkSetVector3Macro(SpecularColor, double); + vtkGetVector3Macro(SpecularColor, double); + + // Description: + // Turn on/off the visibility of edges. On some renderers it is + // possible to render the edges of geometric primitives separately + // from the interior. + vtkGetMacro(EdgeVisibility, int); + vtkSetMacro(EdgeVisibility, int); + vtkBooleanMacro(EdgeVisibility, int); + + // Description: + // Set/Get the color of primitive edges (if edge visibility is enabled). + vtkSetVector3Macro(EdgeColor, double); + vtkGetVector3Macro(EdgeColor, double); + + // Description: + // Set/Get the width of a Line. The width is expressed in screen units. + // This is only implemented for OpenGL. The default is 1.0. + vtkSetClampMacro(LineWidth, float, 0, VTK_FLOAT_MAX); + vtkGetMacro(LineWidth, float); + + // Description: + // Set/Get the stippling pattern of a Line, as a 16-bit binary pattern + // (1 = pixel on, 0 = pixel off). + // This is only implemented for OpenGL. The default is 0xFFFF. + vtkSetMacro(LineStipplePattern, int); + vtkGetMacro(LineStipplePattern, int); + + // Description: + // Set/Get the stippling repeat factor of a Line, which specifies how + // many times each bit in the pattern is to be repeated. + // This is only implemented for OpenGL. The default is 1. + vtkSetClampMacro(LineStippleRepeatFactor, int, 1, VTK_INT_MAX); + vtkGetMacro(LineStippleRepeatFactor, int); + + // Description: + // Set/Get the diameter of a point. The size is expressed in screen units. + // This is only implemented for OpenGL. The default is 1.0. + vtkSetClampMacro(PointSize, float, 0, VTK_FLOAT_MAX); + vtkGetMacro(PointSize, float); + + // Description: + // Turn on/off fast culling of polygons based on orientation of normal + // with respect to camera. If backface culling is on, polygons facing + // away from camera are not drawn. + vtkGetMacro(BackfaceCulling, int); + vtkSetMacro(BackfaceCulling, int); + vtkBooleanMacro(BackfaceCulling, int); + + // Description: + // Turn on/off fast culling of polygons based on orientation of normal + // with respect to camera. If frontface culling is on, polygons facing + // towards camera are not drawn. + vtkGetMacro(FrontfaceCulling, int); + vtkSetMacro(FrontfaceCulling, int); + vtkBooleanMacro(FrontfaceCulling, int); + + // Description: + // Get the material representation used for shading. The material will be used + // only when shading is enabled. + vtkGetObjectMacro(Material, vtkXMLMaterial); + + // Description: + // Returns the name of the material currently loaded, if any. + vtkGetStringMacro(MaterialName); + + // Description: + // Load the material. The material can be the name of a + // built-on material or the filename for a VTK material XML description. + void LoadMaterial(const char* name); + + // Description: + // Load the material given the contents of the material file. + void LoadMaterialFromString(const char* materialxml); + + // Description: + // Load the material given the material representation. + void LoadMaterial(vtkXMLMaterial*); + + // Description: + // Enable/Disable shading. When shading is enabled, the + // Material must be set. + vtkSetMacro(Shading, int); + vtkGetMacro(Shading, int); + vtkBooleanMacro(Shading, int); + + // Description: + // Get the Shader program. If Material is not set/or not loaded properly, + // this will return null. + vtkGetObjectMacro(ShaderProgram, vtkShaderProgram2); + + // Description: + // Get the vtkShaderDeviceAdapter2 if set, returns null otherwise. + virtual vtkShaderDeviceAdapter2* GetShaderDeviceAdapter2() + { return NULL; } + + // Description: + // Provide values to initialize shader variables. + // Useful to initialize shader variables that change over time + // (animation, GUI widgets inputs, etc. ) + // - \p name - hardware name of the uniform variable + // - \p numVars - number of variables being set + // - \p x - values + virtual void AddShaderVariable(const char *name, int numVars, int *x); + virtual void AddShaderVariable(const char *name, int numVars, float *x); + virtual void AddShaderVariable(const char *name, int numVars, double *x); + + // Description: + // Methods to provide to add shader variables from tcl. + void AddShaderVariable(const char* name, int v) + { this->AddShaderVariable(name, 1, &v); } + void AddShaderVariable(const char* name, float v) + { this->AddShaderVariable(name, 1, &v); } + void AddShaderVariable(const char* name, double v) + { this->AddShaderVariable(name, 1, &v); } + void AddShaderVariable(const char* name, int v1, int v2) + { + int v[2] = {v1, v2}; + this->AddShaderVariable(name, 2, v); + } + void AddShaderVariable(const char* name, float v1, float v2) + { + float v[2] = {v1, v2}; + this->AddShaderVariable(name, 2, v); + } + void AddShaderVariable(const char* name, double v1, double v2) + { + double v[2] = {v1, v2}; + this->AddShaderVariable(name, 2, v); + } + void AddShaderVariable(const char* name, int v1, int v2, int v3) + { + int v[3] = {v1, v2, v3}; + this->AddShaderVariable(name, 3, v); + } + void AddShaderVariable(const char* name, float v1, float v2, float v3) + { + float v[3] = {v1, v2, v3}; + this->AddShaderVariable(name, 3, v); + } + void AddShaderVariable(const char* name, double v1, double v2, double v3) + { + double v[3] = {v1, v2, v3}; + this->AddShaderVariable(name, 3, v); + } + + // Description: + // Set/Get the texture object to control rendering texture maps. This will + // be a vtkTexture object. A property does not need to have an associated + // texture map and multiple properties can share one texture. Textures + // must be assigned unique names. + void SetTexture(const char* name, vtkTexture* texture); + vtkTexture* GetTexture(const char* name); + + // Description: + // Set/Get the texture object to control rendering texture maps. This will + // be a vtkTexture object. A property does not need to have an associated + // texture map and multiple properties can share one texture. Textures + // must be assigned unique names. + void SetTexture(int unit, vtkTexture* texture); + vtkTexture* GetTexture(int unit); + void RemoveTexture(int unit); + + // Description: + // Remove a texture from the collection. Note that the + // indices of all the subsequent textures, if any, will change. + void RemoveTexture(const char* name); + + // Description: + // Remove all the textures. + void RemoveAllTextures(); + + // Description: + // Returns the number of textures in this property. + int GetNumberOfTextures(); + + // Description: + // Release any graphics resources that are being consumed by this + // property. The parameter window could be used to determine which graphic + // resources to release. + virtual void ReleaseGraphicsResources(vtkWindow *win); + +//BTX + // Description: + // Used to specify which texture unit a texture will use. + // Only relevant when multitexturing. + enum VTKTextureUnit + { + VTK_TEXTURE_UNIT_0 = 0, + VTK_TEXTURE_UNIT_1, + VTK_TEXTURE_UNIT_2, + VTK_TEXTURE_UNIT_3, + VTK_TEXTURE_UNIT_4, + VTK_TEXTURE_UNIT_5, + VTK_TEXTURE_UNIT_6, + VTK_TEXTURE_UNIT_7 + }; +//ETX + +protected: + vtkPropertyXMLParser(); + ~vtkPropertyXMLParser(); + + // Description: + // Computes composite color. Used by GetColor(). + static void ComputeCompositeColor(double result[3], + double ambient, const double ambient_color[3], + double diffuse, const double diffuse_color[3], + double specular, const double specular_color[3]); + + // Description: + // Load property iVar values from the Material XML. + void LoadProperty(); + void LoadTextures(); + void LoadTexture(vtkXMLDataElement*); + void LoadPerlineNoise(vtkXMLDataElement*); + void LoadMember(vtkXMLDataElement*); + + double Color[3]; + double AmbientColor[3]; + double DiffuseColor[3]; + double SpecularColor[3]; + double EdgeColor[3]; + double Ambient; + double Diffuse; + double Specular; + double SpecularPower; + double Opacity; + float PointSize; + float LineWidth; + int LineStipplePattern; + int LineStippleRepeatFactor; + int Interpolation; + int Representation; + int EdgeVisibility; + int BackfaceCulling; + int FrontfaceCulling; + bool Lighting; + + int Shading; + + char* MaterialName; + vtkSetStringMacro(MaterialName); + + vtkShaderProgram2* ShaderProgram; + void SetShaderProgram(vtkShaderProgram2*); + + vtkXMLMaterial* Material; // TODO: I wonder if this reference needs to be maintained. + + // Description: + // Read this->Material from new style shaders. + // Default implementation is empty. + virtual void ReadFrameworkMaterial(); + +//BTX + // These friends are provided only for the time being + // till we device a graceful way of loading texturing for GLSL. + friend class vtkGLSLShaderProgram; + friend class vtkShader; + // FIXME: + // Don't use these methods. They will be removed. They are provided only + // for the time-being. + vtkTexture* GetTextureAtIndex(int index); + int GetTextureUnitAtIndex(int index); + int GetTextureUnit(const char* name); +//ETX + +private: + vtkPropertyXMLParser(const vtkPropertyXMLParser&); // Not implemented. + void operator=(const vtkPropertyXMLParser&); // Not implemented. + + vtkPropertyInternals* Internals; +}; + +// Description: +// Return the method of shading as a descriptive character string. +inline const char *vtkPropertyXMLParser::GetInterpolationAsString(void) +{ + if (this->Interpolation == VTK_FLAT) + { + return "Flat"; + } + else if (this->Interpolation == VTK_GOURAUD) + { + return "Gouraud"; + } + else + { + return "Phong"; + } +} + +// Description: +// Return the method of shading as a descriptive character string. +inline const char *vtkPropertyXMLParser::GetRepresentationAsString(void) +{ + if (this->Representation == VTK_POINTS) + { + return "Points"; + } + else if (this->Representation == VTK_WIREFRAME) + { + return "Wireframe"; + } + else + { + return "Surface"; + } +} + +#endif diff --git a/Modules/Shaders/vtkXMLMaterial.cxx b/Modules/Shaders/vtkXMLMaterial.cxx index 91381489a9..6855dac6dc 100644 --- a/Modules/Shaders/vtkXMLMaterial.cxx +++ b/Modules/Shaders/vtkXMLMaterial.cxx @@ -1,235 +1,264 @@ /*========================================================================= Program: Visualization Toolkit Module: vtkXMLMaterial.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ #include "vtkXMLMaterial.h" #include "vtkObjectFactory.h" #include "vtkSmartPointer.h" #include "vtkXMLDataElement.h" #include "vtkXMLMaterialParser.h" #include "vtkXMLShader.h" #include #include class vtkXMLMaterialInternals { public: typedef std::vector VectorOfElements; typedef std::vector > VectorOfShaders; VectorOfElements Properties; VectorOfShaders VertexShaders; VectorOfShaders FragmentShaders; VectorOfElements Textures; void Initialize() { this->Properties.clear(); this->VertexShaders.clear(); this->FragmentShaders.clear(); this->Textures.clear(); } }; vtkStandardNewMacro(vtkXMLMaterial); //----------------------------------------------------------------------------- vtkXMLMaterial::vtkXMLMaterial() { this->RootElement = 0; this->Internals = new vtkXMLMaterialInternals; } //----------------------------------------------------------------------------- vtkXMLMaterial::~vtkXMLMaterial() { this->SetRootElement(0); delete this->Internals; } +vtkXMLMaterial* vtkXMLMaterial::CreateInstance(const char* name) +{ + if (!name) + { + return 0; + } + + vtkXMLMaterialParser* parser = vtkXMLMaterialParser::New(); + vtkXMLMaterial* material = vtkXMLMaterial::New(); + parser->SetMaterial(material); + + // First, look for material library files. + // Then, look for Repository files. + + char* filename = vtkXMLShader::LocateFile(name); + if (filename) + { + parser->SetFileName( filename ); + delete [] filename; + parser->Parse(); + parser->Delete(); + return material; + } + + parser->Delete(); + material->Delete(); + return NULL; +} + //----------------------------------------------------------------------------- void vtkXMLMaterial::SetRootElement(vtkXMLDataElement* root) { this->Internals->Initialize(); vtkSetObjectBodyMacro(RootElement, vtkXMLDataElement, root); if (this->RootElement) { // Update the internal data structure to // avoid repeated searches. int numElems = this->RootElement->GetNumberOfNestedElements(); for (int i=0; iRootElement->GetNestedElement(i); const char* name = elem->GetName(); if (!name) { continue; } if (strcmp(name, "Property") == 0) { this->Internals->Properties.push_back(elem); } else if (strcmp(name, "Shader") == 0) { vtkXMLShader* shader = vtkXMLShader::New(); shader->SetRootElement(elem); switch (shader->GetScope()) { case vtkXMLShader::SCOPE_VERTEX: this->Internals->VertexShaders.push_back(shader); break; case vtkXMLShader::SCOPE_FRAGMENT: this->Internals->FragmentShaders.push_back(shader); break; default: vtkErrorMacro("Invalid scope for shader: " << shader->GetName()); } shader->Delete(); } else if (strcmp(name, "Texture") == 0) { this->Internals->Textures.push_back(elem); } } } } //----------------------------------------------------------------------------- int vtkXMLMaterial::GetNumberOfProperties() { return static_cast(this->Internals->Properties.size()); } //----------------------------------------------------------------------------- int vtkXMLMaterial::GetNumberOfTextures() { return static_cast(this->Internals->Textures.size()); } //----------------------------------------------------------------------------- int vtkXMLMaterial::GetNumberOfVertexShaders() { return static_cast(this->Internals->VertexShaders.size()); } //----------------------------------------------------------------------------- int vtkXMLMaterial::GetNumberOfFragmentShaders() { return static_cast(this->Internals->FragmentShaders.size()); } //----------------------------------------------------------------------------- vtkXMLDataElement* vtkXMLMaterial::GetProperty(int id) { if (id < this->GetNumberOfProperties()) { return this->Internals->Properties[id]; } return NULL; } //----------------------------------------------------------------------------- vtkXMLDataElement* vtkXMLMaterial::GetTexture(int index) { if (index < this->GetNumberOfTextures()) { return this->Internals->Textures[index]; } return NULL; } //----------------------------------------------------------------------------- vtkXMLShader* vtkXMLMaterial::GetVertexShader(int id) { if (id < this->GetNumberOfVertexShaders()) { return this->Internals->VertexShaders[id].GetPointer(); } return NULL; } //----------------------------------------------------------------------------- vtkXMLShader* vtkXMLMaterial::GetFragmentShader(int id) { if (id < this->GetNumberOfFragmentShaders()) { return this->Internals->FragmentShaders[id].GetPointer(); } return NULL; } //---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Description: // Get the style the shaders. // \post valid_result: result==1 || result==2 int vtkXMLMaterial::GetShaderStyle() { int result = 1; int vStyle = 0; if (this->GetVertexShader()) { vStyle = this->GetVertexShader()->GetStyle(); } int fStyle = 0; if (this->GetFragmentShader()) { fStyle=this->GetFragmentShader()->GetStyle(); } if (vStyle!=0 && fStyle!=0 && vStyle!=fStyle) { vtkErrorMacro(<<"vertex shader and fragment shader style differ."); } else { if (vStyle!=0) { result = vStyle; } else { result = fStyle; } } assert("post: valid_result" && (result==1 || result==2) ); return result; } //----------------------------------------------------------------------------- void vtkXMLMaterial::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); os << indent << "Number of Properties: " << this->GetNumberOfProperties() << endl; os << indent << "Number of Vertex Shaders: " << this->GetNumberOfVertexShaders() << endl; os << indent << "Number of Fragment Shaders: " << this->GetNumberOfFragmentShaders() << endl; os << indent << "RootElement: "; if (this->RootElement) { os << endl; this->RootElement->PrintSelf(os, indent.GetNextIndent()); } else { os << "(null)" << endl; } } diff --git a/Modules/Shaders/vtkXMLMaterial.h b/Modules/Shaders/vtkXMLMaterial.h index 83912d8d92..622aa37c4b 100644 --- a/Modules/Shaders/vtkXMLMaterial.h +++ b/Modules/Shaders/vtkXMLMaterial.h @@ -1,103 +1,103 @@ /*========================================================================= Program: Visualization Toolkit Module: vtkXMLMaterial.h Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ // .NAME vtkXMLMaterial - encapsulates a VTK Material description. // .SECTION Description // vtkXMLMaterial encapsulates VTK Material description. It keeps a pointer // to vtkXMLDataElement that defines the material and provides // access to Shaders/Properties defined in it. // .SECTION Thanks // Shader support in VTK includes key contributions by Gary Templet at // Sandia National Labs. #ifndef __vtkXMLMaterial_h #define __vtkXMLMaterial_h #include "vtkRenderingCoreModule.h" // For export macro #include "vtkObject.h" class vtkXMLDataElement; class vtkXMLMaterialInternals; class vtkXMLShader; class VTKRENDERINGCORE_EXPORT vtkXMLMaterial : public vtkObject { public: static vtkXMLMaterial* New(); vtkTypeMacro(vtkXMLMaterial, vtkObject); void PrintSelf(ostream& os, vtkIndent indent); // Description: // Create a new instance. It searches for the material // using the following order: first, check the MaterialLibrary; second, // treat the name as an absolute path and try to locate it; third, // search the Material repository. Returns null is it fails to // locate the material. -// static vtkXMLMaterial* CreateInstance(const char* name); + static vtkXMLMaterial* CreateInstance(const char* name); // Description: // Get number of elements of type Property. int GetNumberOfProperties(); // Description: // Get number of elements of type Texture. int GetNumberOfTextures(); // Description: // Get number of Vertex shaders. int GetNumberOfVertexShaders(); // Description: // Get number of fragment shaders. int GetNumberOfFragmentShaders(); // Description: // Get the ith vtkXMLDataElement of type . vtkXMLDataElement* GetProperty(int id=0); // Description: // Get the ith vtkXMLDataElement of type . vtkXMLDataElement* GetTexture(int id=0); // Description: // Get the ith vtkXMLDataElement of type . vtkXMLShader* GetVertexShader(int id=0); // Description: // Get the ith vtkXMLDataElement of type . vtkXMLShader* GetFragmentShader(int id=0); // Description: // Get/Set the XML root element that describes this material. vtkGetObjectMacro(RootElement, vtkXMLDataElement); void SetRootElement(vtkXMLDataElement*); // Description: // Get the style the shaders. // \post valid_result: result==1 || result==2 int GetShaderStyle(); protected: vtkXMLMaterial(); ~vtkXMLMaterial(); vtkXMLDataElement* RootElement; vtkXMLMaterialInternals* Internals; private: vtkXMLMaterial(const vtkXMLMaterial&); // Not implemented. void operator=(const vtkXMLMaterial&); // Not implemented. }; #endif