[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29598] branches/soc-2010-leifandersen/ tests: 1.

Leif Andersen leif.a.andersen at gmail.com
Mon Jun 21 23:25:54 CEST 2010


Revision: 29598
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29598
Author:   leifandersen
Date:     2010-06-21 23:25:54 +0200 (Mon, 21 Jun 2010)

Log Message:
-----------
1.  Some more modifications to the physics tests

2.  Added perceptual image diff, by Matt estela's recomendation, unfortunately, it can't compile due to some failures to declare printf and fprintf, not sure why though, the precompiled binaries work.

Modified Paths:
--------------
    branches/soc-2010-leifandersen/tests/CMakeLists.txt
    branches/soc-2010-leifandersen/tests/pyunit/ops/physics/particle_image.py
    branches/soc-2010-leifandersen/tests/pyunit/ops/physics/runtests.cmake

Added Paths:
-----------
    branches/soc-2010-leifandersen/tests/perceptualdiff/
    branches/soc-2010-leifandersen/tests/perceptualdiff/CMakeLists.txt
    branches/soc-2010-leifandersen/tests/perceptualdiff/CompareArgs.cpp
    branches/soc-2010-leifandersen/tests/perceptualdiff/CompareArgs.h
    branches/soc-2010-leifandersen/tests/perceptualdiff/LPyramid.cpp
    branches/soc-2010-leifandersen/tests/perceptualdiff/LPyramid.h
    branches/soc-2010-leifandersen/tests/perceptualdiff/Metric.cpp
    branches/soc-2010-leifandersen/tests/perceptualdiff/Metric.h
    branches/soc-2010-leifandersen/tests/perceptualdiff/PerceptualDiff.cpp
    branches/soc-2010-leifandersen/tests/perceptualdiff/PerceptualDiff.sln
    branches/soc-2010-leifandersen/tests/perceptualdiff/PerceptualDiff.vcproj
    branches/soc-2010-leifandersen/tests/perceptualdiff/README.txt
    branches/soc-2010-leifandersen/tests/perceptualdiff/RGBAImage.cpp
    branches/soc-2010-leifandersen/tests/perceptualdiff/RGBAImage.h
    branches/soc-2010-leifandersen/tests/perceptualdiff/gpl.txt

Modified: branches/soc-2010-leifandersen/tests/CMakeLists.txt
===================================================================
--- branches/soc-2010-leifandersen/tests/CMakeLists.txt	2010-06-21 20:10:59 UTC (rev 29597)
+++ branches/soc-2010-leifandersen/tests/CMakeLists.txt	2010-06-21 21:25:54 UTC (rev 29598)
@@ -26,3 +26,4 @@
 ENABLE_TESTING()
 ADD_SUBDIRECTORY(gtest)
 ADD_SUBDIRECTORY(pyunit)
+#ADD_SUBDIRECTORY(perceptualdiff)

Added: branches/soc-2010-leifandersen/tests/perceptualdiff/CMakeLists.txt
===================================================================
--- branches/soc-2010-leifandersen/tests/perceptualdiff/CMakeLists.txt	                        (rev 0)
+++ branches/soc-2010-leifandersen/tests/perceptualdiff/CMakeLists.txt	2010-06-21 21:25:54 UTC (rev 29598)
@@ -0,0 +1,69 @@
+PROJECT (PerceptualDiff)
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
+
+SET(DIFF_SRC PerceptualDiff.cpp LPyramid.cpp RGBAImage.cpp
+CompareArgs.cpp Metric.cpp)
+
+ADD_EXECUTABLE (perceptualdiff ${DIFF_SRC})
+
+INSTALL(TARGETS perceptualdiff DESTINATION bin)
+
+# look for freeimage
+FIND_PATH(FREEIMAGE_INCLUDE_DIR FreeImage.h
+  /usr/local/include
+  /usr/include
+  /opt/local/include
+)
+FIND_LIBRARY(FREEIMAGE_LIBRARY freeimage
+  /usr/lib
+  /usr/local/lib
+  /opt/local/lib
+)
+
+IF(FREEIMAGE_INCLUDE_DIR)
+  IF(FREEIMAGE_LIBRARY)
+    SET( FREEIMAGE_FOUND "YES" )
+    SET( FREEIMAGE_LIBRARIES ${FREEIMAGE_LIBRARY} )
+  ENDIF(FREEIMAGE_LIBRARY)
+ENDIF(FREEIMAGE_INCLUDE_DIR)
+
+IF(FREEIMAGE_FOUND)
+  INCLUDE_DIRECTORIES(${FREEIMAGE_INCLUDE_DIR})
+  TARGET_LINK_LIBRARIES(perceptualdiff ${FREEIMAGE_LIBRARY})
+ENDIF(FREEIMAGE_FOUND)
+
+#
+# Packing stuff
+#
+set(CPACK_PACKAGE_VERSION_MAJOR "1")
+set(CPACK_PACKAGE_VERSION_MINOR "1")
+set(CPACK_PACKAGE_VERSION_PATCH "1")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An image comparison utility.")
+set(CPACK_PACKAGE_VENDOR "pdiff dev team")
+set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.txt)
+set(CPACK_GENERATOR TGZ)
+set(
+CPACK_SOURCE_PACKAGE_FILE_NAME
+"PerceptualDiff-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}"
+CACHE INTERNAL "tarball basename"
+)
+set(CPACK_SOURCE_GENERATOR TGZ)
+# The following components are regex's to match anywhere (unless anchored)
+# in absolute path + filename to find files or directories to be excluded
+# from source tarball.
+set(CPACK_SOURCE_IGNORE_FILES
+"~$"
+"\\\\.cvsignore$"
+"^${PROJECT_SOURCE_DIR}/CMakeFiles/"
+"^${PROJECT_SOURCE_DIR}/CMakeCache.txt"
+"^${PROJECT_SOURCE_DIR}/CPackSourceConfig.cmake"
+"^${PROJECT_SOURCE_DIR}/CPackConfig.cmake"
+"^${PROJECT_SOURCE_DIR}/Makefile"
+"^${PROJECT_SOURCE_DIR}/_CPack_Packages"
+"^${PROJECT_SOURCE_DIR}/test/"
+"^${PROJECT_SOURCE_DIR}/cmake_install.cmake"
+)
+include(CPack)
+
+

Added: branches/soc-2010-leifandersen/tests/perceptualdiff/CompareArgs.cpp
===================================================================
--- branches/soc-2010-leifandersen/tests/perceptualdiff/CompareArgs.cpp	                        (rev 0)
+++ branches/soc-2010-leifandersen/tests/perceptualdiff/CompareArgs.cpp	2010-06-21 21:25:54 UTC (rev 29598)
@@ -0,0 +1,159 @@
+/*
+Comapre Args
+Copyright (C) 2006 Yangli Hector Yee
+
+This program is free software; you can redistribute it and/or modify it under the terms of the
+GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
+or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with this program;
+if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "CompareArgs.h"
+#include "RGBAImage.h"
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+static const char* copyright = 
+"PerceptualDiff version 1.1.1, Copyright (C) 2006 Yangli Hector Yee\n\
+PerceptualDiff comes with ABSOLUTELY NO WARRANTY;\n\
+This is free software, and you are welcome\n\
+to redistribute it under certain conditions;\n\
+See the GPL page for details: http://www.gnu.org/copyleft/gpl.html\n\n";
+
+static const char *usage =
+"PeceptualDiff image1.tif image2.tif\n\n\
+   Compares image1.tif and image2.tif using a perceptually based image metric\n\
+   Options:\n\
+\t-verbose       : Turns on verbose mode\n\
+\t-fov deg       : Field of view in degrees (0.1 to 89.9)\n\
+\t-threshold p	 : #pixels p below which differences are ignored\n\
+\t-gamma g       : Value to convert rgb into linear space (default 2.2)\n\
+\t-luminance l   : White luminance (default 100.0 cdm^-2)\n\
+\t-luminanceonly : Only consider luminance; ignore chroma (color) in the comparison\n\
+\t-colorfactor   : How much of color to use, 0.0 to 1.0, 0.0 = ignore color.\n\
+\t-downsample    : How many powers of two to down sample the image.\n\
+\t-output o.ppm  : Write difference to the file o.ppm\n\
+\n\
+\n Note: Input or Output files can also be in the PNG or JPG format or any format\
+\n that FreeImage supports.\
+\n";
+
+CompareArgs::CompareArgs()
+{
+	ImgA = NULL;
+	ImgB = NULL;
+	ImgDiff = NULL;
+	Verbose = false;
+	LuminanceOnly = false;
+	FieldOfView = 45.0f;
+	Gamma = 2.2f;
+	ThresholdPixels = 100;
+	Luminance = 100.0f;
+   ColorFactor = 1.0f;
+   DownSample = 0;
+}
+
+CompareArgs::~CompareArgs()
+{
+	if (ImgA) delete ImgA;
+	if (ImgB) delete ImgB;
+	if (ImgDiff) delete ImgDiff;
+}
+
+bool CompareArgs::Parse_Args(int argc, char **argv)
+{
+	if (argc < 3) {
+		ErrorStr = copyright;
+		ErrorStr += usage;
+		return false;
+	}
+	int image_count = 0;
+	const char* output_file_name = NULL;
+	for (int i = 1; i < argc; i++) {
+		if (strcmp(argv[i], "-fov") == 0) {
+			if (++i < argc) {
+				FieldOfView = (float) atof(argv[i]);
+			}
+		} else if (strcmp(argv[i], "-verbose") == 0) {
+			Verbose = true;
+		} else if (strcmp(argv[i], "-threshold") == 0) {
+			if (++i < argc) {
+				ThresholdPixels = atoi(argv[i]);
+			}
+		} else if (strcmp(argv[i], "-gamma") == 0) {
+			if (++i < argc) {
+				Gamma = (float) atof(argv[i]);
+			}
+		} else if (strcmp(argv[i], "-luminance") == 0) {
+			if (++i < argc) {
+				Luminance = (float) atof(argv[i]);
+			}
+		} else if (strcmp(argv[i], "-luminanceonly") == 0) {
+			LuminanceOnly = true;
+		} else if (strcmp(argv[i], "-colorfactor") == 0) {
+			if (++i < argc) {
+				ColorFactor = (float) atof(argv[i]);
+			}
+		} else if (strcmp(argv[i], "-downsample") == 0) {
+			if (++i < argc) {
+				DownSample = (int) atoi(argv[i]);
+			}
+		} else if (strcmp(argv[i], "-output") == 0) {
+			if (++i < argc) {
+				output_file_name = argv[i];
+			}
+		} else if (image_count < 2) {
+			RGBAImage* img = RGBAImage::ReadFromFile(argv[i]);
+			if (!img) {
+				ErrorStr = "FAIL: Cannot open ";
+				ErrorStr += argv[i];
+				ErrorStr += "\n";
+				return false;
+			} else {
+				++image_count;
+				if(image_count == 1)
+					ImgA = img;
+				else
+					ImgB = img;
+			}
+		} else {
+			fprintf(stderr, "Warning: option/file \"%s\" ignored\n", argv[i]);
+		}
+	} // i
+	if(!ImgA || !ImgB) {
+		ErrorStr = "FAIL: Not enough image files specified\n";
+		return false;
+	}
+   for (int i = 0; i < DownSample; i++) {
+      if (Verbose) printf("Downsampling by %d\n", 1 << (i+1));
+      RGBAImage *tmp = ImgA->DownSample();
+      if (tmp) {
+         delete ImgA;
+         ImgA = tmp;
+      }
+      tmp = ImgB->DownSample();
+      if (tmp) {
+         delete ImgB;
+         ImgB = tmp;
+      }
+   }
+	if(output_file_name) {
+		ImgDiff = new RGBAImage(ImgA->Get_Width(), ImgA->Get_Height(), output_file_name);
+	}
+	return true;
+}
+
+void CompareArgs::Print_Args()
+{
+	printf("Field of view is %f degrees\n", FieldOfView);
+	printf("Threshold pixels is %d pixels\n", ThresholdPixels);
+	printf("The Gamma is %f\n", Gamma);
+	printf("The Display's luminance is %f candela per meter squared\n", Luminance);
+}

Added: branches/soc-2010-leifandersen/tests/perceptualdiff/CompareArgs.h
===================================================================
--- branches/soc-2010-leifandersen/tests/perceptualdiff/CompareArgs.h	                        (rev 0)
+++ branches/soc-2010-leifandersen/tests/perceptualdiff/CompareArgs.h	2010-06-21 21:25:54 UTC (rev 29598)
@@ -0,0 +1,51 @@
+/*
+Comapre Args
+Copyright (C) 2006 Yangli Hector Yee
+
+This program is free software; you can redistribute it and/or modify it under the terms of the
+GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
+or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with this program;
+if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef _COMPAREARGS_H
+#define _COMPAREARGS_H
+
+#include <string>
+
+class RGBAImage;
+
+// Args to pass into the comparison function
+class CompareArgs
+{
+public:
+	CompareArgs();
+	~CompareArgs();
+	bool Parse_Args(int argc, char **argv);	
+	void Print_Args();
+	
+	RGBAImage		*ImgA;				// Image A
+	RGBAImage		*ImgB;				// Image B
+	RGBAImage		*ImgDiff;			// Diff image
+	bool			Verbose;			// Print lots of text or not
+	bool			LuminanceOnly;		// Only consider luminance; ignore chroma channels in the comparison.
+	float			FieldOfView;		// Field of view in degrees
+	float			Gamma;				// The gamma to convert to linear color space
+	float			Luminance;			// the display's luminance
+	unsigned int	ThresholdPixels;	// How many pixels different to ignore
+	std::string		ErrorStr;			// Error string
+  // How much color to use in the metric.
+  // 0.0 is the same as LuminanceOnly = true,
+  // 1.0 means full strength.
+  float ColorFactor;
+  // How much to down sample image before comparing, in powers of 2.
+  int DownSample;
+};
+
+#endif

Added: branches/soc-2010-leifandersen/tests/perceptualdiff/LPyramid.cpp
===================================================================
--- branches/soc-2010-leifandersen/tests/perceptualdiff/LPyramid.cpp	                        (rev 0)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list