Commit 32a3fc4c authored by Francois Bertel's avatar Francois Bertel
Browse files

ENH:Moved vtkVREncodeString from VolumeRendering to Utilities/EncodeString and...

ENH:Moved vtkVREncodeString from VolumeRendering to Utilities/EncodeString and renamed it as vtkEncodeString since it can be used to encode any text file into a C string, not only for GLSL or other shader code but also for encoding event logs in Widgets/Testing for example
parent 19098eca
......@@ -38,6 +38,8 @@ IF(VTK_INCLUDE_NEED_TCL)
SUBDIRS(TclTk)
ENDIF(VTK_INCLUDE_NEED_TCL)
SUBDIRS(EncodeString)
IF(VTK_USE_RENDERING)
SUBDIRS(ftgl ParseOGLExt)
ENDIF(VTK_USE_RENDERING)
......
# 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.
#
IF(NOT CMAKE_CROSSCOMPILING)
ADD_EXECUTABLE(vtkEncodeString vtkEncodeString.cxx)
EXPORT(TARGETS vtkEncodeString FILE ${EXPORT_EXECUTABLES_FILE} NAMESPACE "${EXPORT_EXECUTABLES_NAMESPACE}" APPEND)
ENDIF(NOT CMAKE_CROSSCOMPILING)
IF(CMAKE_CROSSCOMPILING)
SET(ENCODESTRING_EXE vtkEncodeString)
ELSE(CMAKE_CROSSCOMPILING)
GET_TARGET_PROPERTY(ENCODESTRING_EXE vtkEncodeString LOCATION)
ENDIF(CMAKE_CROSSCOMPILING)
SET(VTK_ENCODESTRING_EXE ${ENCODESTRING_EXE}
CACHE INTERNAL "String encoder." FORCE)
#include "vtkObject.h"
/*=========================================================================
Program: Visualization Toolkit
Module: vtkEncodeString.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.
=========================================================================*/
// Encode a string in a C++ file from a text file.
// For example, it can be used to encode a GLSL source file (in Rendering or
// VolumeRendering) or an event log (in Widgets/Testing).
#include "vtkSystemIncludes.h" // for cout,endl
#include <vtkstd/string>
#include <vtksys/ios/sstream>
......@@ -11,23 +29,27 @@ public:
}
Output(const Output&);
void operator=(const Output&);
~Output(){}
~Output()
{
}
vtksys_ios::ostringstream Stream;
int ProcessFile(const char* file, const char* title)
bool ProcessFile(const char *inputFile,
const char *stringName)
{
FILE* fp = fopen(file, "r");
if ( !fp )
FILE *fp=fopen(inputFile, "r");
if(!fp)
{
cout << "Canot open file: " << file << endl;
return VTK_ERROR;
cout << "Cannot open file: " << inputFile
<< " (check path and permissions)" << endl;
return false;
}
int ch;
this->Stream << "// Define the " << title << " interfaces." << endl
<< "//" << endl
<< "// Generated from file: " << file << endl
this->Stream << "// Define the " << stringName << " string." << endl
<< "//" << endl
<< "// Generated from file: " << inputFile << endl
<< "//" << endl
<< "const char* " << title << " ="
<< "const char* " << stringName << " ="
<< endl << "\"";
while ( ( ch = fgetc(fp) ) != EOF )
{
......@@ -50,38 +72,38 @@ public:
}
this->Stream << "\\n\";" << endl;
fclose(fp);
return VTK_OK;
return true;
}
};
int main(int argc, char* argv[])
int main(int argc,
char *argv[])
{
if ( argc < 4 )
if(argc<4)
{
cout << "Usage: " << argv[0] << " <output-file> <input-path> <title>" << endl;
cout << "Encode a string in a C++ file from a text file." << endl;
cout << "Usage: " << argv[0] << " <output-file> <input-path> <stringname>"
<< endl;
return 1;
}
Output ot;
ot.Stream << "// Loadable modules" << endl
<< "//" << endl
<< "// Generated by " << argv[0] << endl
<< "//" << endl
<< "#ifndef __vtkKWCommonPro" << argv[3] << "_h" << endl
<< "#define __vtkKWCommonPro" << argv[3] << "_h" << endl
<< "" << endl;
ot.Stream << "// DO NOT EDIT." << endl
<< "// Generated by " << argv[0] << endl;
vtkstd::string output = argv[1];
vtkstd::string input = argv[2];
if ( ot.ProcessFile(input.c_str(), argv[3]) != VTK_OK )
if(!ot.ProcessFile(input.c_str(), argv[3]))
{
cout << "Problem generating header file from XML file: " << input.c_str() << endl;
cout << "Problem generating c++ file from source text file: " <<
input.c_str() << endl;
return 1;
}
ot.Stream << "" << endl
<< "#endif" << endl;
FILE* fp = fopen(output.c_str(), "w");
if ( !fp )
ot.Stream << endl;
FILE *fp=fopen(output.c_str(),"w");
if(!fp)
{
cout << "Cannot open output file: " << output.c_str() << endl;
return 1;
......
......@@ -68,20 +68,6 @@ SET( KitOpenGL_SRCS
# Stuff we need for the vtkVolumeTextureMapper3D
#-------------------------------------------------
# Create an executable to encode source files into C string literals.
IF(NOT CMAKE_CROSSCOMPILING)
ADD_EXECUTABLE(vtkVREncodeString
${VTK_SOURCE_DIR}/VolumeRendering/vtkVREncodeString.cxx
)
EXPORT(TARGETS vtkVREncodeString FILE ${EXPORT_EXECUTABLES_FILE} NAMESPACE "${EXPORT_EXECUTABLES_NAMESPACE}" APPEND)
ENDIF(NOT CMAKE_CROSSCOMPILING)
IF(CMAKE_CROSSCOMPILING)
SET(ENCODE_EXE vtkVREncodeString)
ELSE(CMAKE_CROSSCOMPILING)
GET_TARGET_PROPERTY(ENCODE_EXE vtkVREncodeString LOCATION)
ENDIF(CMAKE_CROSSCOMPILING)
# The set of source files to be encoded.
SET(asm_files
vtkHAVSVolumeMapper_kbufferVP
......@@ -106,8 +92,8 @@ FOREACH(file ${asm_files})
SET(res ${VTK_BINARY_DIR}/VolumeRendering/${file}.cxx)
ADD_CUSTOM_COMMAND(
OUTPUT ${res}
DEPENDS ${src} vtkVREncodeString
COMMAND ${ENCODE_EXE}
DEPENDS ${src} vtkEncodeString
COMMAND ${VTK_ENCODESTRING_EXE}
ARGS ${res} ${src} ${file}
)
SET(Kit_EXTRA_SRCS ${Kit_EXTRA_SRCS} ${res})
......@@ -186,3 +172,11 @@ INCLUDE(${VTK_CMAKE_DIR}/KitCommonBlock.cmake)
# Make sure vtkRendering is built before vtkVolumeRendering builds.
# This will make sure vtkgl.h exists.
ADD_DEPENDENCIES(vtkVolumeRendering vtkRendering)
# when crosscompiling vtkEncodeString is imported, don't add a dependency to it
# this should be handled by cmake so it doesn't have to be done here
IF(NOT CMAKE_CROSSCOMPILING)
# Add target dependency to ensure the vtkEncodeString is built before
# VolumeRendering is.
ADD_DEPENDENCIES(vtk${KIT} vtkEncodeString)
ENDIF(NOT CMAKE_CROSSCOMPILING)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment