Full Code of sergeytulyakov/FaceCept3D for AI

master f13c791af154 cached
128 files
331.9 KB
88.2k tokens
139 symbols
1 requests
Download .txt
Showing preview only (369K chars total). Download the full file or copy to clipboard to get everything.
Repository: sergeytulyakov/FaceCept3D
Branch: master
Commit: f13c791af154
Files: 128
Total size: 331.9 KB

Directory structure:
gitextract_pxarii44/

├── .gitignore
├── FaceCept3D/
│   ├── 3dheadposeestimation.sln
│   ├── CMakeLists.txt
│   ├── Config/
│   │   ├── CommonProperties.props
│   │   ├── CommonPropertiesLibsDebug.props
│   │   └── CommonPropertiesLibsRelease.props
│   ├── HeadPoseEstimationFramework/
│   │   ├── Align/
│   │   │   ├── CloudMapper.cpp
│   │   │   ├── CloudMapper.h
│   │   │   ├── IHeadTemplateCreator.h
│   │   │   ├── IncrementalHeadTemplateCreator.cpp
│   │   │   ├── IncrementalHeadTemplateCreator.h
│   │   │   ├── TransformationEstimationHPE.cpp
│   │   │   └── TransformationEstimationHPE.h
│   │   ├── CMakeLists.txt
│   │   ├── Common.h
│   │   ├── Converter/
│   │   │   ├── IDataConverter.h
│   │   │   ├── KinectDataConverter.cpp
│   │   │   └── KinectDataConverter.h
│   │   ├── DataFilter/
│   │   │   └── IDataFilter.h
│   │   ├── DataObject/
│   │   │   ├── CloudXYZRGBA.h
│   │   │   ├── HeadPoseInfo.h
│   │   │   ├── IDataObject.h
│   │   │   ├── IDataStorage.h
│   │   │   ├── LandmarksObject.h
│   │   │   ├── MapDataStorage.cpp
│   │   │   ├── MapDataStorage.h
│   │   │   └── RawFrames.h
│   │   ├── Detector/
│   │   │   └── DepthFrameDetector/
│   │   │       ├── DepthDetector.cpp
│   │   │       ├── DepthDetector.h
│   │   │       ├── LeafNode.cpp
│   │   │       ├── LeafNode.h
│   │   │       ├── Tree.cpp
│   │   │       ├── Tree.h
│   │   │       ├── csvMat.cpp
│   │   │       ├── csvMat.h
│   │   │       ├── localFunctions.cpp
│   │   │       └── localFunctions.h
│   │   ├── Exception/
│   │   │   ├── HPEException.cpp
│   │   │   └── HPEException.h
│   │   ├── FacialExpressions/
│   │   │   ├── ferLocalFunctions.cpp
│   │   │   └── ferLocalFunctions.h
│   │   ├── Features/
│   │   │   ├── Calculator/
│   │   │   │   ├── CylinderOptimizedFeatureCalculator.cpp
│   │   │   │   ├── CylinderOptimizedFeatureCalculator.h
│   │   │   │   ├── FeatureCalculatorBase.h
│   │   │   │   └── IFeatureCalculator.h
│   │   │   ├── IFeature.h
│   │   │   └── Sampler/
│   │   │       ├── CylinderSampler.cpp
│   │   │       ├── CylinderSampler.h
│   │   │       └── IPatchSampler.h
│   │   ├── Filter/
│   │   │   ├── BoxFilter.h
│   │   │   ├── CenteredBoxFilter.h
│   │   │   ├── FilteringQueue.h
│   │   │   ├── Filters.h
│   │   │   ├── FunctorFilter.h
│   │   │   ├── ICenterCloudFilter.h
│   │   │   ├── ICloudFilter.h
│   │   │   └── MovingLeastSquaresFilter.h
│   │   ├── Grabber/
│   │   │   ├── GrabberBase.cpp
│   │   │   ├── GrabberBase.h
│   │   │   ├── OpenNIGrabber.cpp
│   │   │   ├── OpenNIGrabber.h
│   │   │   ├── PCDGrabber.cpp
│   │   │   ├── PCDGrabber.h
│   │   │   ├── ProviderGrabber.cpp
│   │   │   └── ProviderGrabber.h
│   │   ├── HeadPoseEstimationFramework.vcxproj
│   │   ├── Helpers/
│   │   │   ├── HpeHelpers.cpp
│   │   │   └── HpeHelpers.h
│   │   ├── Interface/
│   │   │   └── IInterface.h
│   │   ├── Landmarks.h
│   │   ├── Processor/
│   │   │   ├── ConverterProcessor.cpp
│   │   │   ├── ConverterProcessor.h
│   │   │   ├── DepthPreprocessingProcessor.cpp
│   │   │   ├── DepthPreprocessingProcessor.h
│   │   │   ├── DetectorProcessor.cpp
│   │   │   ├── DetectorProcessor.h
│   │   │   ├── FacialExpressionsProcessor.cpp
│   │   │   ├── FacialExpressionsProcessor.h
│   │   │   ├── FilterProcessor.cpp
│   │   │   ├── FilterProcessor.h
│   │   │   ├── HeadExtractionProcessor.cpp
│   │   │   ├── HeadExtractionProcessor.h
│   │   │   ├── IProcessor.h
│   │   │   ├── SaveCloudProcessor.cpp
│   │   │   ├── SaveCloudProcessor.h
│   │   │   ├── ShowCloudProcessor.cpp
│   │   │   ├── ShowCloudProcessor.h
│   │   │   ├── TemplateCreatorProcessor.cpp
│   │   │   ├── TemplateCreatorProcessor.h
│   │   │   ├── TrackingProcessor.cpp
│   │   │   └── TrackingProcessor.h
│   │   ├── Provider/
│   │   │   ├── IDataProvider.h
│   │   │   ├── RawDataProvider.cpp
│   │   │   └── RawDataProvider.h
│   │   ├── Settings/
│   │   │   ├── HPESettings.cpp
│   │   │   └── HPESettings.h
│   │   ├── Tracker/
│   │   │   └── ICPTemplateTracker.h
│   │   ├── UI/
│   │   │   ├── PointPicker.h
│   │   │   ├── ShowCloud.h
│   │   │   ├── ShowMesh.h
│   │   │   └── VisualizerCommon.h
│   │   └── WindowsOnly/
│   │       ├── Grabber/
│   │       │   ├── KinectSDKGrabber.cpp
│   │       │   └── KinectSDKGrabber.h
│   │       └── Processor/
│   │           ├── KinectSDKConverterProcessor.cpp
│   │           └── KinectSDKConverterProcessor.h
│   ├── TemplateCreator/
│   │   ├── CMakeLists.txt
│   │   ├── TemplateCreator.cpp
│   │   ├── TemplateCreator.vcxproj
│   │   ├── UIProcessor.cpp
│   │   ├── UIProcessor.h
│   │   ├── settings.ini
│   │   ├── stdafx.cpp
│   │   └── stdafx.h
│   └── TemplateTracker/
│       ├── ShowTwoCloudsProcessor.cpp
│       ├── ShowTwoCloudsProcessor.h
│       ├── TemplateTracker.cpp
│       ├── TemplateTracker.vcxproj
│       ├── UIProcessor.cpp
│       ├── UIProcessor.h
│       ├── VisuilizeProcessor.cpp
│       ├── VisuilizeProcessor.h
│       ├── VoxelizeProcessor.cpp
│       ├── VoxelizeProcessor.h
│       ├── settings.ini
│       ├── stdafx.cpp
│       └── stdafx.h
├── LICENSE
└── README.md

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
*.suo
*.sdf
*.user
*.opensdf
*.txt
*.idea
!CMakeLists.txt

build
ipch
Debug
Release
x64
data/DetectorData
data/FERData

================================================
FILE: FaceCept3D/3dheadposeestimation.sln
================================================

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HeadPoseEstimationFramework", "HeadPoseEstimationFramework\HeadPoseEstimationFramework.vcxproj", "{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TemplateCreator", "TemplateCreator\TemplateCreator.vcxproj", "{39EBEEC1-29C0-48BA-9858-E593CAEE7757}"
	ProjectSection(ProjectDependencies) = postProject
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD} = {A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}
	EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TemplateTracker", "TemplateTracker\TemplateTracker.vcxproj", "{68A9917E-A682-4013-8D30-389AB45A9E0D}"
	ProjectSection(ProjectDependencies) = postProject
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD} = {A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}
	EndProjectSection
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Mixed Platforms = Debug|Mixed Platforms
		Debug|Win32 = Debug|Win32
		Debug|x64 = Debug|x64
		Release|Mixed Platforms = Release|Mixed Platforms
		Release|Win32 = Release|Win32
		Release|x64 = Release|x64
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}.Debug|Win32.ActiveCfg = Debug|x64
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}.Debug|x64.ActiveCfg = Debug|x64
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}.Debug|x64.Build.0 = Debug|x64
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}.Release|Mixed Platforms.ActiveCfg = Release|x64
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}.Release|Win32.ActiveCfg = Release|x64
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}.Release|x64.ActiveCfg = Release|x64
		{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}.Release|x64.Build.0 = Release|x64
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Debug|Mixed Platforms.Build.0 = Debug|Win32
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Debug|Win32.ActiveCfg = Debug|Win32
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Debug|Win32.Build.0 = Debug|Win32
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Debug|x64.ActiveCfg = Debug|x64
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Debug|x64.Build.0 = Debug|x64
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Release|Mixed Platforms.ActiveCfg = Release|Win32
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Release|Mixed Platforms.Build.0 = Release|Win32
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Release|Win32.ActiveCfg = Release|Win32
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Release|Win32.Build.0 = Release|Win32
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Release|x64.ActiveCfg = Release|x64
		{39EBEEC1-29C0-48BA-9858-E593CAEE7757}.Release|x64.Build.0 = Release|x64
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Debug|Mixed Platforms.Build.0 = Debug|Win32
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Debug|Win32.ActiveCfg = Debug|Win32
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Debug|Win32.Build.0 = Debug|Win32
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Debug|x64.ActiveCfg = Debug|x64
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Debug|x64.Build.0 = Debug|x64
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Release|Mixed Platforms.ActiveCfg = Release|Win32
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Release|Mixed Platforms.Build.0 = Release|Win32
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Release|Win32.ActiveCfg = Release|Win32
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Release|Win32.Build.0 = Release|Win32
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Release|x64.ActiveCfg = Release|x64
		{68A9917E-A682-4013-8D30-389AB45A9E0D}.Release|x64.Build.0 = Release|x64
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


================================================
FILE: FaceCept3D/CMakeLists.txt
================================================
cmake_minimum_required(VERSION 2.8)

add_subdirectory(HeadPoseEstimationFramework)
add_subdirectory(TemplateCreator)


================================================
FILE: FaceCept3D/Config/CommonProperties.props
================================================
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <IncludePath>$(KINECTSDK10_DIR)/inc;$(FACECEPT3D_3RDPARTY_DIR)\Boost\include;$(FACECEPT3D_3RDPARTY_DIR)\Eigen\include;$(FACECEPT3D_3RDPARTY_DIR)\FLANN\include;$(FACECEPT3D_3RDPARTY_DIR)\Opencv\include;$(FACECEPT3D_3RDPARTY_DIR)\PCL\include;$(FACECEPT3D_3RDPARTY_DIR)\Qhull\include;$(FACECEPT3D_3RDPARTY_DIR)\Qt\include;$(FACECEPT3D_3RDPARTY_DIR)\VTK\include\vtk-5.8;$(ProjectDir);$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include</IncludePath>
    <_PropertySheetDisplayName>CommonPropertiesPaths</_PropertySheetDisplayName>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <ClCompile />
    <ClCompile>
      <AdditionalOptions>/Zm500 %(AdditionalOptions)</AdditionalOptions>
    </ClCompile>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

================================================
FILE: FaceCept3D/Config/CommonPropertiesLibsDebug.props
================================================
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <PropertyGroup>
    <LibraryPath>$(KINECTSDK10_DIR)\lib\amd64;$(FACECEPT3D_3RDPARTY_DIR)\Boost\lib;$(FACECEPT3D_3RDPARTY_DIR)\FLANN\lib;$(FACECEPT3D_3RDPARTY_DIR)\Opencv\lib;$(FACECEPT3D_3RDPARTY_DIR)\PCL\lib;$(FACECEPT3D_3RDPARTY_DIR)\Qhull\lib;$(FACECEPT3D_3RDPARTY_DIR)\Qt\lib;$(FACECEPT3D_3RDPARTY_DIR)\VTK\lib\vtk-5.8;$(VCInstallDir)lib\amd64;$(VCInstallDir)atlmfc\lib\amd64;$(WindowsSdkDir)lib\x64</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>HeadPoseEstimationFramework_Debug.lib;opencv_calib3d2410d.lib;opencv_contrib2410d.lib;opencv_core2410d.lib;opencv_features2d2410d.lib;opencv_flann2410d.lib;opencv_gpu2410d.lib;opencv_highgui2410d.lib;opencv_imgproc2410d.lib;opencv_legacy2410d.lib;opencv_ml2410d.lib;opencv_nonfree2410d.lib;opencv_objdetect2410d.lib;opencv_ocl2410d.lib;opencv_photo2410d.lib;opencv_stitching2410d.lib;opencv_superres2410d.lib;opencv_ts2410d.lib;opencv_video2410d.lib;opencv_videostab2410d.lib;Kinect10.lib;opengl32.lib;qhullstatic_d.lib;pcl_common_debug.lib;pcl_features_debug.lib;pcl_filters_debug.lib;pcl_io_debug.lib;pcl_io_ply_debug.lib;pcl_kdtree_debug.lib;pcl_keypoints_debug.lib;pcl_octree_debug.lib;pcl_outofcore_debug.lib;pcl_people_debug.lib;pcl_recognition_debug.lib;pcl_registration_debug.lib;pcl_sample_consensus_debug.lib;pcl_search_debug.lib;pcl_segmentation_debug.lib;pcl_surface_debug.lib;pcl_tracking_debug.lib;pcl_visualization_debug.lib;flann_cpp_s-gd.lib;libboost_atomic-vc100-mt-gd-1_55.lib;libboost_chrono-vc100-mt-gd-1_55.lib;libboost_context-vc100-mt-gd-1_55.lib;libboost_coroutine-vc100-mt-gd-1_55.lib;libboost_date_time-vc100-mt-gd-1_55.lib;libboost_exception-vc100-mt-gd-1_55.lib;libboost_filesystem-vc100-mt-gd-1_55.lib;libboost_graph-vc100-mt-gd-1_55.lib;libboost_iostreams-vc100-mt-gd-1_55.lib;libboost_locale-vc100-mt-gd-1_55.lib;libboost_log_setup-vc100-mt-gd-1_55.lib;libboost_log-vc100-mt-gd-1_55.lib;libboost_math_c99f-vc100-mt-gd-1_55.lib;libboost_math_c99l-vc100-mt-gd-1_55.lib;libboost_math_c99-vc100-mt-gd-1_55.lib;libboost_math_tr1f-vc100-mt-gd-1_55.lib;libboost_math_tr1l-vc100-mt-gd-1_55.lib;libboost_math_tr1-vc100-mt-gd-1_55.lib;libboost_prg_exec_monitor-vc100-mt-gd-1_55.lib;libboost_program_options-vc100-mt-gd-1_55.lib;libboost_random-vc100-mt-gd-1_55.lib;libboost_regex-vc100-mt-gd-1_55.lib;libboost_serialization-vc100-mt-gd-1_55.lib;libboost_signals-vc100-mt-gd-1_55.lib;libboost_system-vc100-mt-gd-1_55.lib;libboost_test_exec_monitor-vc100-mt-gd-1_55.lib;libboost_thread-vc100-mt-gd-1_55.lib;libboost_timer-vc100-mt-gd-1_55.lib;libboost_unit_test_framework-vc100-mt-gd-1_55.lib;libboost_wave-vc100-mt-gd-1_55.lib;libboost_wserialization-vc100-mt-gd-1_55.lib;phonond4.lib;QAxContainerd.lib;QAxServerd.lib;Qt3Supportd4.lib;QtCLucened4.lib;QtCored4.lib;QtDeclaratived4.lib;QtDesignerComponentsd4.lib;QtDesignerd4.lib;QtGuid4.lib;QtHelpd4.lib;qtmaind.lib;QtMultimediad4.lib;QtNetworkd4.lib;QtOpenGLd4.lib;QtScriptd4.lib;QtScriptToolsd4.lib;QtSqld4.lib;QtSvgd4.lib;QtTestd4.lib;QtUiToolsd.lib;QtWebKitd4.lib;QtXmld4.lib;QtXmlPatternsd4.lib;MapReduceMPI-gd.lib;mpistubs-gd.lib;QVTK-gd.lib;vtkalglib-gd.lib;vtkCharts-gd.lib;vtkCommon-gd.lib;vtkDICOMParser-gd.lib;vtkexoIIc-gd.lib;vtkexpat-gd.lib;vtkFiltering-gd.lib;vtkfreetype-gd.lib;vtkftgl-gd.lib;vtkGenericFiltering-gd.lib;vtkGeovis-gd.lib;vtkGraphics-gd.lib;vtkhdf5-gd.lib;vtkHybrid-gd.lib;vtkImaging-gd.lib;vtkInfovis-gd.lib;vtkIO-gd.lib;vtkjpeg-gd.lib;vtklibxml2-gd.lib;vtkmetaio-gd.lib;vtkNetCDF-gd.lib;vtkNetCDF_cxx-gd.lib;vtkpng-gd.lib;vtkproj4-gd.lib;vtkRendering-gd.lib;vtksqlite-gd.lib;vtksys-gd.lib;vtktiff-gd.lib;vtkverdict-gd.lib;vtkViews-gd.lib;vtkVolumeRendering-gd.lib;vtkWidgets-gd.lib;vtkzlib-gd.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

================================================
FILE: FaceCept3D/Config/CommonPropertiesLibsRelease.props
================================================
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <PropertyGroup>
    <LibraryPath>$(KINECTSDK10_DIR)\lib\amd64;$(FACECEPT3D_3RDPARTY_DIR)\Boost\lib;$(FACECEPT3D_3RDPARTY_DIR)\FLANN\lib;$(FACECEPT3D_3RDPARTY_DIR)\Opencv\lib;$(FACECEPT3D_3RDPARTY_DIR)\PCL\lib;$(FACECEPT3D_3RDPARTY_DIR)\Qhull\lib;$(FACECEPT3D_3RDPARTY_DIR)\Qt\lib;$(FACECEPT3D_3RDPARTY_DIR)\VTK\lib\vtk-5.8;$(VCInstallDir)lib\amd64;$(VCInstallDir)atlmfc\lib\amd64;$(WindowsSdkDir)lib\x64</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>HeadPoseEstimationFramework_Release.lib;Kinect10.lib;opengl32.lib;MapReduceMPI.lib;mpistubs.lib;QVTK.lib;vtkalglib.lib;vtkCharts.lib;vtkCommon.lib;vtkDICOMParser.lib;vtkexoIIc.lib;vtkexpat.lib;vtkFiltering.lib;vtkfreetype.lib;vtkftgl.lib;vtkGenericFiltering.lib;vtkGeovis.lib;vtkGraphics.lib;vtkhdf5.lib;vtkHybrid.lib;vtkImaging.lib;vtkInfovis.lib;vtkIO.lib;vtkjpeg.lib;vtklibxml2.lib;vtkmetaio.lib;vtkNetCDF.lib;vtkNetCDF_cxx.lib;vtkpng.lib;vtkproj4.lib;vtkRendering.lib;vtksqlite.lib;vtksys.lib;vtktiff.lib;vtkverdict.lib;vtkViews.lib;vtkVolumeRendering.lib;vtkWidgets.lib;vtkzlib.lib;opencv_calib3d2410.lib;opencv_contrib2410.lib;opencv_core2410.lib;opencv_features2d2410.lib;opencv_flann2410.lib;opencv_gpu2410.lib;opencv_highgui2410.lib;opencv_imgproc2410.lib;opencv_legacy2410.lib;opencv_ml2410.lib;opencv_nonfree2410.lib;opencv_objdetect2410.lib;opencv_ocl2410.lib;opencv_photo2410.lib;opencv_stitching2410.lib;opencv_superres2410.lib;opencv_ts2410.lib;opencv_video2410.lib;opencv_videostab2410.lib;qhullstatic.lib;pcl_common_release.lib;pcl_features_release.lib;pcl_filters_release.lib;pcl_io_ply_release.lib;pcl_io_release.lib;pcl_kdtree_release.lib;pcl_keypoints_release.lib;pcl_octree_release.lib;pcl_outofcore_release.lib;pcl_people_release.lib;pcl_recognition_release.lib;pcl_registration_release.lib;pcl_sample_consensus_release.lib;pcl_search_release.lib;pcl_segmentation_release.lib;pcl_surface_release.lib;pcl_tracking_release.lib;pcl_visualization_release.lib;flann_cpp_s.lib;libboost_atomic-vc100-mt-1_55.lib;libboost_chrono-vc100-mt-1_55.lib;libboost_context-vc100-mt-1_55.lib;libboost_coroutine-vc100-mt-1_55.lib;libboost_date_time-vc100-mt-1_55.lib;libboost_exception-vc100-mt-1_55.lib;libboost_filesystem-vc100-mt-1_55.lib;libboost_graph-vc100-mt-1_55.lib;libboost_iostreams-vc100-mt-1_55.lib;libboost_locale-vc100-mt-1_55.lib;libboost_log-vc100-mt-1_55.lib;libboost_log_setup-vc100-mt-1_55.lib;libboost_math_c99-vc100-mt-1_55.lib;libboost_math_c99f-vc100-mt-1_55.lib;libboost_math_c99l-vc100-mt-1_55.lib;libboost_math_tr1-vc100-mt-1_55.lib;libboost_math_tr1f-vc100-mt-1_55.lib;libboost_math_tr1l-vc100-mt-1_55.lib;libboost_prg_exec_monitor-vc100-mt-1_55.lib;libboost_program_options-vc100-mt-1_55.lib;libboost_random-vc100-mt-1_55.lib;libboost_regex-vc100-mt-1_55.lib;libboost_serialization-vc100-mt-1_55.lib;libboost_signals-vc100-mt-1_55.lib;libboost_system-vc100-mt-1_55.lib;libboost_test_exec_monitor-vc100-mt-1_55.lib;libboost_thread-vc100-mt-1_55.lib;libboost_timer-vc100-mt-1_55.lib;libboost_unit_test_framework-vc100-mt-1_55.lib;libboost_wave-vc100-mt-1_55.lib;libboost_wserialization-vc100-mt-1_55.lib;phonon4.lib;QAxContainer.lib;QAxServer.lib;Qt3Support4.lib;QtCLucene4.lib;QtCore4.lib;QtDeclarative4.lib;QtDesigner4.lib;QtDesignerComponents4.lib;QtGui4.lib;QtHelp4.lib;qtmain.lib;QtMultimedia4.lib;QtNetwork4.lib;QtOpenGL4.lib;QtScript4.lib;QtScriptTools4.lib;QtSql4.lib;QtSvg4.lib;QtTest4.lib;QtUiTools.lib;QtWebKit4.lib;QtXml4.lib;QtXmlPatterns4.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Align/CloudMapper.cpp
================================================
#include "CloudMapper.h"

#include <pcl/common/common.h>

#include <pcl/registration/registration.h>

#include <pcl/registration/icp.h>
#include <pcl/registration/correspondence_rejection_sample_consensus.h>
#include <pcl/registration/transformation_estimation_point_to_plane.h>
#include <pcl/registration/transformation_estimation_point_to_plane_weighted.h>
#include <pcl/registration/transformation_estimation_svd_scale.h>
#include <pcl/registration/correspondence_estimation_normal_shooting.h>
#include <pcl/visualization/cloud_viewer.h>

#include <pcl/features/normal_3d.h>

#include <pcl/correspondence.h>
#include <pcl/search/kdtree.h>

#include <boost/format.hpp>
#include <boost/thread.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/thread_time.hpp>

#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>

#include "UI/ShowCloud.h"
#include "Exception/HPEException.h"
#include "Filter/Filters.h"
#include "TransformationEstimationHPE.h"

#include <pcl/io/pcd_io.h>

namespace hpe
{
    float CalculateDistance(pcl::PointXYZRGBA &p1, pcl::PointXYZRGBA &p2)
    {
        Eigen::VectorXf d(3);
        d(0) = p1.x - p2.x;
        d(1) = p1.y - p2.y;
        d(2) = p1.z - p2.z;

        return d.norm();
    }

    CloudMapper::CloudMapper()
        : m_icpParams(CloudMapper::ICPParams(0.05, 0.05, 0.000001, 100000, 100)),
          m_useDynamicICP(false), m_usePointToPlaneMetric(false), m_useNormalShooting(false),
          m_estimateScale(false)

    {

    }

    void CloudMapper::AddCloud(CloudMapper::Cloud::Ptr &cloud, CloudMapper::Landmarks &landmarks)
    {
        m_pointClouds.push_back(cloud);
        m_landmarks.push_back(landmarks);
    }

    CloudMapper::Clouds CloudMapper::GetAlignedClouds(TransformationsPtr transformations)
    {
        return AlignAll(m_pointClouds, m_landmarks);
    }

    CloudMapper::Cloud::Ptr CloudMapper::GetMergedCloud()
    {
        CloudMapper::Clouds alignedClouds = AlignAll(m_pointClouds, m_landmarks);
        CloudMapper::Cloud::Ptr merged(new CloudMapper::Cloud);
        auto it = alignedClouds.begin();
        do
        {
            auto current = (*it);
            *merged += *current;
            ++it;
        }
        while (it != alignedClouds.end());

        return merged;
    }

    CloudMapper::TransformationsPtr CloudMapper::GetTransforms()
    {
        CloudMapper::TransformationsPtr transforms(new CloudMapper::Transformations);

        AlignAll(m_pointClouds, m_landmarks, transforms);

        return transforms;
    }

    void CloudMapper::SetICPParams(CloudMapper::ICPParams params)
    {
        m_icpParams = params;
    }

    void CloudMapper::SetDynamicICPParams(CloudMapper::DynamicICPParams &params)
    {
        m_dynamicICPParams = params;
        SetUseDynamicICP(true);
    }

    void CloudMapper::SetUseDynamicICP(bool use)
    {
        m_useDynamicICP = use;
    }

    void CloudMapper::SetUseNormalShooting(bool use)
    {
        m_useNormalShooting = use;
    }

    void CloudMapper::SetEstimateScale(bool estimateScale)
    {
        m_estimateScale = estimateScale;
    }

    void CloudMapper::SetUsePointToPlaneMetric(bool use)
    {
        m_usePointToPlaneMetric = use;
    }

    Eigen::Matrix4f CloudMapper::GetTransformForTwoCloudsPointToPlane(CloudMapper::Cloud::Ptr &source,
            CloudMapper::Cloud::Ptr &target,
            ICPParams params)
    {
        CloudMapper::NormalCloud::Ptr normalSource(new CloudMapper::NormalCloud);
        pcl::copyPointCloud(*source, *normalSource);

        CloudMapper::NormalCloud::Ptr normalTarget(new CloudMapper::NormalCloud);
        pcl::copyPointCloud(*target, *normalTarget);

        typedef pcl::search::KdTree<CloudMapper::PointNormal> Search2;
        Search2::Ptr search(new Search2);

        pcl::NormalEstimation<CloudMapper::PointNormal, CloudMapper::PointNormal> estimation;
        estimation.setSearchMethod(search);
        estimation.setKSearch(10);
        estimation.setInputCloud(normalTarget);
        estimation.compute(*normalTarget);

        typedef pcl::registration::CorrespondenceRejectorSampleConsensus<CloudMapper::PointNormal> Rejector;

        pcl::Registration<CloudMapper::PointNormal, CloudMapper::PointNormal>::Ptr registration(new pcl::IterativeClosestPoint<CloudMapper::PointNormal, CloudMapper::PointNormal>);

        pcl::registration::CorrespondenceRejectorSampleConsensus<CloudMapper::PointNormal>::Ptr rejector(new pcl::registration::CorrespondenceRejectorSampleConsensus<CloudMapper::PointNormal>);
        rejector->setInlierThreshold(params.RansacRejectionThreshold);
        rejector->setMaximumIterations(params.MaxRANSACIterations);
        rejector->setInputSource(normalSource);
        rejector->setInputTarget(normalTarget);
        registration->setInputSource(normalSource);
        registration->setInputTarget(normalTarget);
        registration->setMaxCorrespondenceDistance(params.MaxCorrespondenceDistance);
        registration->setRANSACOutlierRejectionThreshold(params.RansacRejectionThreshold);
        registration->setTransformationEpsilon(params.TransformationEpsilon);
        registration->setMaximumIterations(params.MaxICPIterations);
        registration->setRANSACIterations(params.MaxRANSACIterations);
        registration->addCorrespondenceRejector(rejector);

        if (m_useNormalShooting)
        {
            typedef pcl::registration::CorrespondenceEstimationNormalShooting<CloudMapper::PointNormal, CloudMapper::PointNormal, CloudMapper::PointNormal> NormalShooting;
            NormalShooting::Ptr ce(new NormalShooting);
            registration->setCorrespondenceEstimation(ce);
        }

        typedef TransformationEstimationHPE<CloudMapper::PointNormal, CloudMapper::PointNormal> Custom;
        Custom::Ptr metric(new Custom);
        metric->SetWeights(m_weights);
        registration->setTransformationEstimation(metric);

        CloudMapper::NormalCloud::Ptr c(new CloudMapper::NormalCloud);
        registration->align(*c);
        //std::cout << "Fitness Score " << registration->getFitnessScore() << std::endl;

        return registration->getFinalTransformation();
    }

    Eigen::Matrix4f CloudMapper::GetTransformForTwoCloudsPointToPoint(CloudMapper::Cloud::Ptr &source,
            CloudMapper::Cloud::Ptr &target,
            ICPParams params)
    {
        pcl::Registration<CloudMapper::PointType, CloudMapper::PointType>::Ptr registration(new pcl::IterativeClosestPoint<CloudMapper::PointType, CloudMapper::PointType>);
        typedef pcl::registration::CorrespondenceRejectorSampleConsensus<CloudMapper::PointType> Rejector;

        Rejector::Ptr rejector(new Rejector);
        rejector->setInlierThreshold(params.RansacRejectionThreshold);
        rejector->setMaximumIterations(params.MaxRANSACIterations);
        rejector->setInputSource(source);
        rejector->setInputTarget(target);

        registration->setInputSource(source);
        registration->setInputTarget(target);
        registration->setMaxCorrespondenceDistance(params.MaxCorrespondenceDistance);
        registration->setRANSACOutlierRejectionThreshold(params.RansacRejectionThreshold);
        registration->setTransformationEpsilon(params.TransformationEpsilon);
        registration->setMaximumIterations(params.MaxICPIterations);
        registration->setRANSACIterations(params.MaxRANSACIterations);
        registration->addCorrespondenceRejector(rejector);

        CloudMapper::Cloud::Ptr c(new CloudMapper::Cloud);
        registration->align(*c);

        std::cout << "Fitness Score " << registration->getFitnessScore() << std::endl;

        return registration->getFinalTransformation();
    }

    Eigen::Matrix4f CloudMapper::GetTransformForTwoCloudsDynamically(CloudMapper::Cloud::Ptr &source,
            CloudMapper::Cloud::Ptr &target,
            CloudMapper::DynamicICPParams &dynamicParams)
    {

        int icpRound = 1;

        CloudMapper::Cloud::Ptr result(new Cloud);
        pcl::copyPointCloud(*source, *result);
        Eigen::Matrix4f finalTransformationMatrix = Eigen::Matrix4f::Identity();
        for (auto it = dynamicParams.begin(); it != dynamicParams.end(); ++it)
        {
            auto params = *it;
            Eigen::Matrix4f stepTransform = Eigen::Matrix4f::Identity();

            if (m_usePointToPlaneMetric)
            {
                stepTransform = GetTransformForTwoCloudsPointToPlane(result, target, params);
            }
            else
            {
                stepTransform = GetTransformForTwoCloudsPointToPoint(result, target, params);
            }

            pcl::transformPointCloud(*result, *result, stepTransform);

            finalTransformationMatrix = finalTransformationMatrix * stepTransform;
        }

        return finalTransformationMatrix;
    }

    Eigen::Matrix4f CloudMapper::GetTransformHavingLandmarks(CloudMapper::Cloud::Ptr &source, Common<CloudMapper::PointType>::Landmarks &l1,
            CloudMapper::Cloud::Ptr &target, Common<CloudMapper::PointType>::Landmarks &l2)
    {
        pcl::CorrespondencesPtr correspondences = LandmarksToCorresponencies(source, l1, target, l2);
        return GetTransformHavingCorrespondences(source, target, correspondences);
    }

    Eigen::Matrix4f CloudMapper::GetTransformHavingCorrespondences(CloudMapper::Cloud::Ptr &source, CloudMapper::Cloud::Ptr &target, pcl::CorrespondencesPtr &correspondences)
    {
        Eigen::Matrix4f initialAlignmentMatrix = ComputeInitialAlignment(source, target, correspondences);
        bool initialAlignmentSucceed = IsNotNAN(initialAlignmentMatrix);

        CloudMapper::Cloud::Ptr sourceTransformed(new CloudMapper::Cloud);
        if (initialAlignmentSucceed)
        {
            pcl::transformPointCloud(*source, *sourceTransformed, initialAlignmentMatrix);
        }
        else
        {
            sourceTransformed = source;
        }

        if (m_estimateScale)
        {
            ShowTwoCloudsInDifferentColors<CloudMapper::PointType>(sourceTransformed, target, pcl::CorrespondencesPtr(), "After IA");
        }

        CloudMapper::DynamicICPParams dynamicParams = m_dynamicICPParams;
        if (m_useDynamicICP == false)
        {
            dynamicParams.push_back(m_icpParams);
        }

        CloudMapper::Cloud::Ptr result = sourceTransformed;
        Eigen::Matrix4f finalTransformationMatrix = GetTransformForTwoCloudsDynamically(sourceTransformed, target, dynamicParams);


        Eigen::Matrix4f totalTransform;
        if (initialAlignmentSucceed)
        {
            totalTransform = finalTransformationMatrix * initialAlignmentMatrix;
        }
        else
        {
            totalTransform = finalTransformationMatrix;
        }

        pcl::transformPointCloud(*source, *result, totalTransform);

        return totalTransform;
    }

    CloudMapper::Clouds CloudMapper::AlignAll(CloudMapper::Clouds &clouds, CloudMapper::LandmarksVector &landmarksVector, TransformationsPtr transformations)
    {
        TransformationsPtr allTransformations(new Transformations);
        if (transformations != nullptr)
        {
            allTransformations = transformations;
        }

        if (clouds.size() != landmarksVector.size())
        {
            throw HPEException("CloudMapper::AlignAll - clouds.size() != landmarksVector.size()");
        }

        std::vector<Eigen::Matrix4f> stepTransformations;

        pcl::PointCloud<CloudMapper::PointType>::Ptr sourceCloud = clouds[0];

        for (int cloudIndex = 1; cloudIndex < clouds.size() - 1; cloudIndex++)
        {
            int sourceIndex = cloudIndex;
            int targetIndex = sourceIndex + 1;

            pcl::PointCloud<CloudMapper::PointType>::Ptr targetCloud = clouds[targetIndex];

            auto totalTransform = GetTransformHavingLandmarks(sourceCloud, landmarksVector[sourceIndex],
                                  targetCloud, landmarksVector[targetIndex]);

            Eigen::Matrix3f rotationMatrix = totalTransform.block<3, 3>(0, 0);
            Eigen::Vector3f translationVector = totalTransform.block<3, 1>(0, 3);
            Eigen::Quaternionf quaternion(rotationMatrix);
            Eigen::Matrix3f rotation2(quaternion);

            pcl::transformPointCloud(*sourceCloud, *sourceCloud, totalTransform);
            pcl::PointCloud<CloudMapper::PointType>::Ptr newCloud(new pcl::PointCloud<CloudMapper::PointType>);
            *sourceCloud += *targetCloud;
            sourceCloud = Voxelize<CloudMapper::PointType>(sourceCloud, 0.006f);

            //ShowCloud<CloudMapper::PointType>(sourceCloud);

            if (IsNotNAN(totalTransform) == false)
            {
                int q = 42;
            }

            std::cout << cloudIndex << std::endl;

            stepTransformations.push_back(totalTransform);
        }

        ShowCloud<CloudMapper::PointType>(sourceCloud);

        CloudMapper::Clouds result;

        auto targetCloud = clouds[clouds.size() - 1];

        for (int cloudIndex = 0; cloudIndex < clouds.size() - 1; cloudIndex++)
        {
            Eigen::Matrix4f accumulatedMatrix = stepTransformations[cloudIndex];

            for (int matrixIndex = cloudIndex + 1; matrixIndex < stepTransformations.size(); matrixIndex++)
            {
                accumulatedMatrix = accumulatedMatrix * stepTransformations[matrixIndex];
            }

            CloudMapper::Cloud::Ptr transformed(new CloudMapper::Cloud);
            pcl::transformPointCloud(*clouds[cloudIndex], *transformed, accumulatedMatrix);
            allTransformations->push_back(accumulatedMatrix);

            result.push_back(transformed);
        }

        result.push_back(targetCloud);

        return result;
    }

    Eigen::Matrix4f CloudMapper::ComputeInitialAlignment(Cloud::Ptr &cloud1, Cloud::Ptr &cloud2, pcl::CorrespondencesPtr &correspondences)
    {
        if (correspondences->empty())
        {
            return Eigen::Matrix4f::Identity();
        }

        pcl::registration::CorrespondenceRejectorSampleConsensus<PointType> sac;
        sac.setInlierThreshold(0.5);
        sac.setInputSource(cloud1);
        sac.setInputTarget(cloud2);
        sac.setInputCorrespondences(correspondences);
        pcl::Correspondences inliers;
        sac.getCorrespondences(inliers);

        Eigen::Matrix4f transformation;
        if (m_estimateScale)
        {
            pcl::registration::TransformationEstimationSVDScale<PointType, PointType> transformationEstimation;
            transformationEstimation.estimateRigidTransformation(*cloud1, *cloud2, inliers, transformation);
        }
        else
        {
            pcl::registration::TransformationEstimationSVD<PointType, PointType> transformationEstimation;
            transformationEstimation.estimateRigidTransformation(*cloud1, *cloud2, inliers, transformation);
        }


        if (transformation == Eigen::Matrix4f::Identity() || IsNotNAN(transformation) == false)
        {
            std::cout << "Identity or NAN" << std::endl;
        }

        return transformation;
    }

    Common<CloudMapper::PointType>::Landmark CloudMapper::FindClosestPoint(CloudMapper::Cloud::Ptr &cloud, CloudMapper::PointType &p)
    {
        pcl::search::KdTree<CloudMapper::PointType> search;
        search.setInputCloud(cloud);

        std::vector<int> indices;
        std::vector<float> distances;
        search.nearestKSearch(p, 1, indices, distances);

        Common<CloudMapper::PointType>::Landmark result;
        result.index = indices[0];
        result.point = cloud->at(indices[0]);

        return result;
    }

    pcl::CorrespondencesPtr CloudMapper::LandmarksToCorresponencies(Cloud::Ptr &cloud1, CloudMapper::Landmarks &landmarks1, Cloud::Ptr &cloud2, CloudMapper::Landmarks &landmarks2)
    {
        pcl::CorrespondencesPtr result(new pcl::Correspondences);

        int resultSize = std::min(landmarks1.size(), landmarks2.size());

        for (int i = 0; i < resultSize; i++)
        {
            auto sourcePoint1 = landmarks1.at(i).point;
            auto sourcePoint2 = landmarks2.at(i).point;

            auto p1IsNotNan = IsNotNAN(sourcePoint1);
            auto p2IsNotNan = IsNotNAN(sourcePoint2);
            if (p1IsNotNan && p2IsNotNan)
            {
                CloudMapper::Landmarks::value_type pt1 = FindClosestPoint(cloud1, sourcePoint1);
                CloudMapper::Landmarks::value_type pt2 = FindClosestPoint(cloud2, sourcePoint2);

                float distance = CalculateDistance(pt1.point, pt2.point);
                pcl::Correspondence correspondence(pt1.index, pt2.index, distance);

                result->push_back(correspondence);
            }
        }

        return result;
    }

    bool CloudMapper::IsNotNAN(const Eigen::Matrix4f &x)
    {
        return ((x.array() == x.array())).all();
    }

    bool CloudMapper::IsNotNAN(CloudMapper::PointType &point)
    {
        return (boost::math::isnan(point.x) || boost::math::isnan(point.y) || boost::math::isnan(point.z)) == false;
    }
}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Align/CloudMapper.h
================================================
#ifndef CLOUDMAPPER_H
#define CLOUDMAPPER_H

#include <memory>


#include <vector>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/correspondence.h>


//#include "Provider_Old/DataProviderOld.h"

#include <Common.h>

namespace hpe
{
    /**
     \class	CloudMapper
    
     \brief	Class that performs Iterative closest point alighment.
    
     */

    class CloudMapper
    {
        public:
            typedef pcl::PointXYZRGBA PointType;
            typedef pcl::PointCloud<PointType> Cloud;

            typedef pcl::PointNormal PointNormal;
            typedef pcl::PointCloud<PointNormal> NormalCloud;

            typedef Common<PointType>::Landmarks Landmarks;
            typedef std::vector<Landmarks> LandmarksVector;
            typedef std::vector<Cloud::Ptr> Clouds;

            typedef std::vector<Eigen::Matrix4f> Transformations;
            typedef std::shared_ptr<std::vector<Eigen::Matrix4f>> TransformationsPtr;

            struct ICPParams
            {
                ICPParams(float distance, float threshold, float epsilon, int maxICPIterations, int maxRansacIterations)
                    : MaxCorrespondenceDistance(distance),
                      RansacRejectionThreshold(threshold),
                      TransformationEpsilon(epsilon),
                      MaxICPIterations(maxICPIterations),
                      MaxRANSACIterations(maxRansacIterations)
                {

                }

                float MaxCorrespondenceDistance;
                float RansacRejectionThreshold;
                float TransformationEpsilon;
                int MaxICPIterations;
                int MaxRANSACIterations;
            };

            typedef std::vector<ICPParams> DynamicICPParams;

            CloudMapper();

            void AddCloud(Cloud::Ptr &cloud, Landmarks &landmarks);
            Clouds GetAlignedClouds(TransformationsPtr transformations = nullptr);
            Cloud::Ptr GetMergedCloud();
            TransformationsPtr GetTransforms();

            void SetICPParams(ICPParams params);
            void SetDynamicICPParams(DynamicICPParams &params);
            void SetUseDynamicICP(bool use);
            void SetUseNormalShooting(bool use);
            void SetEstimateScale(bool estimateScale);
            void SetUsePointToPlaneMetric(bool use);
            void SetWeights(std::vector<double> &weights) {
                m_weights = weights;
            }

            Eigen::Matrix4f GetTransformForTwoCloudsPointToPlane(Cloud::Ptr &source,
                    Cloud::Ptr &target,
                    ICPParams params = ICPParams(0.05, 0.05, 0.000001, 100000, 100));


            Eigen::Matrix4f GetTransformForTwoCloudsPointToPoint(Cloud::Ptr &source,
                    Cloud::Ptr &target,
                    ICPParams params = ICPParams(0.05, 0.05, 0.000001, 100000, 100));

            Eigen::Matrix4f GetTransformForTwoCloudsDynamically(Cloud::Ptr &source,
                    Cloud::Ptr &target,
                    DynamicICPParams &dynamicParams);

            Eigen::Matrix4f GetTransformHavingLandmarks(Cloud::Ptr &source,
                    Common<PointType>::Landmarks &l1,
                    Cloud::Ptr &target,
                    Common<PointType>::Landmarks &l2);

            Eigen::Matrix4f GetTransformHavingCorrespondences(Cloud::Ptr &source,
                    Cloud::Ptr &target,
                    pcl::CorrespondencesPtr &correspondences);


            pcl::CorrespondencesPtr LandmarksToCorresponencies(Cloud::Ptr &cloud1, Landmarks &landmarks1,
                    Cloud::Ptr &cloud2, Landmarks &landmarks2);

            Eigen::Matrix4f ComputeInitialAlignment(Cloud::Ptr &cloud1,
                                                    Cloud::Ptr &cloud2,
                                                    pcl::CorrespondencesPtr &correspondencies);



        private:
            Clouds m_pointClouds;
            LandmarksVector m_landmarks;

            Clouds AlignAll(Clouds &clouds, LandmarksVector &landmarksVector, TransformationsPtr transformations = nullptr);
            static Common<PointType>::Landmark FindClosestPoint(Cloud::Ptr &cloud, PointType &p);

            ICPParams m_icpParams;
            DynamicICPParams m_dynamicICPParams;
            bool m_useDynamicICP;
            bool m_usePointToPlaneMetric;
            bool m_useNormalShooting;
            bool m_estimateScale;

            std::vector<double> m_weights;

            static bool IsNotNAN(const Eigen::Matrix4f &x);
            static bool IsNotNAN(CloudMapper::PointType &point);
    };
}

#endif // CLOUDMAPPER_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Align/IHeadTemplateCreator.h
================================================
#ifndef IHEADTEMPLATECREATOR_H
#define IHEADTEMPLATECREATOR_H

#include <pcl/point_cloud.h>

#include <Interface/IInterface.h>

namespace hpe
{
    template <typename PointType>
    class IHeadTemplateCreator : public IInterface
    {
        public:
            virtual typename pcl::PointCloud<PointType>::Ptr GetTemplate() = 0;
    };
}


#endif // IHEADTEMPLATECREATOR_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Align/IncrementalHeadTemplateCreator.cpp
================================================
#include "IncrementalHeadTemplateCreator.h"
#include <Filter/Filters.h>
#include <pcl/common/io.h>
#include <pcl/common/time.h>
#include <UI/ShowCloud.h>

namespace hpe
{

    IncrementalHeadTemplateCreator::IncrementalHeadTemplateCreator(void)
        : m_template(new CloudType), m_targetCloud(new CloudType)
    {
        m_mapper.SetUseNormalShooting(false);
        m_mapper.SetUsePointToPlaneMetric(true);

        m_icpParams.push_back(CloudMapper::ICPParams(0.03, 0.005, 10e-6, 400, 10));
        m_mapper.SetDynamicICPParams(m_icpParams);

        m_aggregatedTransform = Eigen::Matrix4f::Identity();
    }


    IncrementalHeadTemplateCreator::~IncrementalHeadTemplateCreator(void)
    {
    }

    IncrementalHeadTemplateCreator::CloudType::Ptr IncrementalHeadTemplateCreator::GetTemplate()
    {
        CloudType::Ptr result(new CloudType);
        pcl::copyPointCloud(*m_template, *result);
        return result;
    }

    IncrementalHeadTemplateCreator::CloudType::Ptr IncrementalHeadTemplateCreator::AddCloudToTemplate(CloudType::Ptr cloud)
    {
        if (m_template->points.size() == 0)
        {
            pcl::copyPointCloud(*cloud, *m_template);
            pcl::copyPointCloud(*cloud, *m_targetCloud);
        }
        else
        {
            pcl::ScopeTime t("AddCloudToTemplate");
            Eigen::Matrix4f transformMatrix = m_mapper.GetTransformForTwoCloudsDynamically(cloud, m_targetCloud, m_icpParams);
            m_aggregatedTransform *= transformMatrix;

            CloudType::Ptr transformedSource(new CloudType);

            pcl::transformPointCloud(*cloud, *transformedSource, m_aggregatedTransform);

            *m_template += *transformedSource;
            m_template = Voxelize<PointType>(m_template, 0.001f);

            pcl::copyPointCloud(*cloud, *m_targetCloud);
        }

        return GetTemplate();
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Align/IncrementalHeadTemplateCreator.h
================================================
#pragma once

#ifndef INCREMENTALHEADTEMPLATECREATOR_H
#define INCREMENTALHEADTEMPLATECREATOR_H

#include <Align/IHeadTemplateCreator.h>
#include <Align/CloudMapper.h>

#include <pcl/point_types.h>
#include <pcl/point_cloud.h>

namespace hpe
{
    /**
     \class	IncrementalHeadTemplateCreator
    
     \brief	Class that performs incremental alighment. 
    
     \author	Sergey
     \date	8/11/2015
     */

    class IncrementalHeadTemplateCreator : public IHeadTemplateCreator<pcl::PointXYZRGBA>
    {
        public:
            typedef pcl::PointXYZRGBA PointType;
            typedef pcl::PointCloud<PointType> CloudType;

            IncrementalHeadTemplateCreator(void);
            ~IncrementalHeadTemplateCreator(void);

            CloudType::Ptr GetTemplate();

            CloudType::Ptr AddCloudToTemplate(CloudType::Ptr cloud);

        private:
            CloudType::Ptr m_template;
            CloudType::Ptr m_targetCloud;
            CloudMapper m_mapper;
            CloudMapper::DynamicICPParams m_icpParams;
            Eigen::Matrix4f m_aggregatedTransform;
    };

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Align/TransformationEstimationHPE.cpp
================================================
#include "TransformationEstimationHPE.h"


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Align/TransformationEstimationHPE.h
================================================
#ifndef TRANSFORMATIONESTIMATION_H
#define TRANSFORMATIONESTIMATION_H

#include <pcl/point_cloud.h>

#include <pcl/registration/transformation_estimation_point_to_plane_weighted.h>

namespace hpe
{
	/**
	 \class	TransformationEstimationHPE
	
	 \brief	Class that performs history-based weighting of the points for ICP
			Thanks to this, ICP is speeded up 4 times. The method overloads 
			the standard pcl class to get the desired functionality

	
	 \tparam	PointSource	PointType of the source point cloud.
	 \tparam	PointTarget	PointType of the target point cloud.
	 \tparam	MatScalar  	scalar type.
	 */

	template <typename PointSource, typename PointTarget, typename MatScalar = float>
    class TransformationEstimationHPE : public pcl::registration::TransformationEstimationPointToPlaneWeighted<PointSource, PointTarget, MatScalar>
    {
            typedef TransformationEstimationHPE<PointSource, PointTarget, MatScalar> Self;
            typedef pcl::registration::TransformationEstimationPointToPlaneWeighted<PointSource, PointTarget, MatScalar> Base;
            typedef typename Base::Matrix4 Matrix4;
        public:
            typedef boost::shared_ptr<TransformationEstimationHPE<PointSource, PointTarget, MatScalar>> Ptr;

            TransformationEstimationHPE()
            {
            }

            void SetWeights(std::vector<double> &weights)
            {
                m_weights = weights;
            }

            inline void
            estimateRigidTransformation(
                const pcl::PointCloud<PointSource> &cloud_src,
                const pcl::PointCloud<PointTarget> &cloud_tgt,
                Matrix4 &transformation_matrix) const
            {
                Base::estimateRigidTransformation(cloud_src, cloud_tgt, transformation_matrix);
            }

            inline void
            estimateRigidTransformation(
                const pcl::PointCloud<PointSource> &cloud_src,
                const std::vector<int> &indices_src,
                const pcl::PointCloud<PointTarget> &cloud_tgt,
                Matrix4 &transformation_matrix) const
            {
                Base::estimateRigidTransformation(cloud_src, indices_src, cloud_tgt, transformation_matrix);
            }

            void
            estimateRigidTransformation(
                const pcl::PointCloud<PointSource> &cloud_src,
                const std::vector<int> &indices_src,
                const pcl::PointCloud<PointTarget> &cloud_tgt,
                const std::vector<int> &indices_tgt,
                Matrix4 &transformation_matrix) const
            {
                std::vector<double> weights(indices_src.size());

                if (m_weights.size() != 0)
                {
                    for (int i = 0; i < indices_src.size(); i += 1)
                    {
                        weights[i] = m_weights[indices_src[i]];
                    }
                }
                else
                {
                    for (int i = 0; i < indices_src.size(); i += 1)
                    {
                        weights[i] = 1;
                    }
                }

                Self *self = const_cast<Self *>(this);
                self->Base::setWeights(weights);
                self->Base::setUseCorrespondenceWeights(false);

                Base::estimateRigidTransformation(cloud_src, indices_src, cloud_tgt, indices_tgt, transformation_matrix);
            }

            void
            estimateRigidTransformation(
                const pcl::PointCloud<PointSource> &cloud_src,
                const pcl::PointCloud<PointTarget> &cloud_tgt,
                const pcl::Correspondences &correspondences,
                Matrix4 &transformation_matrix) const
            {
                Base::estimateRigidTransformation(cloud_src, cloud_tgt, correspondences, transformation_matrix);
            }

        private:
            std::vector<double> m_weights;
    };
}

#endif // TRANSFORMATIONESTIMATION_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/CMakeLists.txt
================================================
cmake_minimum_required(VERSION 2.8)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

project(HeadPoseEstimationFramework)

FILE (GLOB_RECURSE SRC_LIST *.cpp *.h)
foreach (SRC ${SRC_LIST})
	string (FIND ${SRC} "WindowsOnly" FOUND)
	if (NOT ${FOUND} EQUAL "-1")
		list (REMOVE_ITEM SRC_LIST ${SRC})
	endif()
endforeach ()

find_package(PCL 1.7 REQUIRED)
find_package(OpenCV REQUIRED)

include_directories(${PCL_INCLUDE_DIRS} ${CMAKE_CURRENT_LIST_DIR})
link_directories(${PCL_LIBRARY_DIRS} ${CMAKE_BINARY_DIR} )
add_definitions(${PCL_DEFINITIONS})

add_library(${PROJECT_NAME} SHARED ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES} ${OpenCV_LIBS})




================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Common.h
================================================
#pragma once

#ifndef COMMON_H
#define COMMON_H

#include <vector>
#include <list>

namespace hpe
{
    template <typename PointType>
    class Common
    {
        public:
            struct Landmark
            {
                Landmark() {}

                Landmark(int i, PointType p)
                    : index(i), point(p)
                {}

                int index;
                PointType point;
            };

            typedef std::vector<Landmark> Landmarks;
    };

    typedef std::vector<int> PointIndexes;
    typedef std::list<PointIndexes> PointHistory;
}

#endif // COMMON_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Converter/IDataConverter.h
================================================
#ifndef IDATACONVERTER_H
#define IDATACONVERTER_H

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <opencv2/opencv.hpp>

#include "Interface/IInterface.h"

namespace hpe
{
    class IDataConverter : public IInterface
    {
        public:
            virtual pcl::PointCloud<pcl::PointXYZRGBA>::Ptr DepthRGBToPointCloud(cv::Mat &depth, cv::Mat &bgr) = 0;

    };
}

#endif // IDATACONVERTER_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Converter/KinectDataConverter.cpp
================================================
#include "KinectDataConverter.h"

#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/math/special_functions/round.hpp>

namespace hpe
{
    typedef union
    {
        struct
        {
            unsigned char Blue;
            unsigned char Green;
            unsigned char Red;
            unsigned char Alpha;
        };
        float float_value;
        uint32_t long_value;
    } RGBValue;

    KinectDataConverter::KinectDataConverter()
    {
    }

    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr KinectDataConverter::DepthRGBToPointCloud(cv::Mat &depth, cv::Mat &bgr)
    {
        cv::Size depthImageSize = depth.size();

        float centerX, centerY;
        float scaleFactorX, scaleFactorY;

        ComputeCameraIntrinsics(depthImageSize, centerX, centerY, scaleFactorX, scaleFactorY);

        pcl::PointCloud<pcl::PointXYZRGBA>::Ptr result(new pcl::PointCloud<pcl::PointXYZRGBA>);
        result->width = depthImageSize.width;
        result->height = depthImageSize.height;
        result->is_dense = false;
        result->points.resize(depthImageSize.width * depthImageSize.height);

        for (int y = 0; y < depthImageSize.height; ++y)
        {
            for (int x = 0; x < depthImageSize.width; ++x)
            {
                pcl::PointXYZRGBA &pt = result->at(x, y);

                float depthValue = (float) depth.at<float>(y, x);

                if (depthValue == -1000.f || depthValue == 0.0f || boost::math::isnan(depthValue))
                {
                    pt.x = pt.y = pt.z = std::numeric_limits<float>::quiet_NaN();
                }
                else
                {
                    //depthValue /= 1000;
                    pt.x = (static_cast<float>(x) - centerX) * scaleFactorX * depthValue;
                    pt.y = (centerY - static_cast<float>(y)) * scaleFactorY * depthValue;
                    pt.z = depthValue;

                    cv::Vec3b colorValue = bgr.at<cv::Vec3b>(y, x);
                    RGBValue color;
                    color.Red = colorValue[2];
                    color.Green = colorValue[1];
                    color.Blue = colorValue[0];
                    pt.rgba = color.long_value;
                }
            }
        }

        return result;
    }

    void KinectDataConverter::ComputeCameraIntrinsics(cv::Size &imageSize, float &centerX, float &centerY, float &scaleFactorX, float &scaleFactorY)
    {
        int dims[] = {imageSize.width, imageSize.height};

        // The 525 factor default is only true for VGA. If not, we should scale
        scaleFactorX = scaleFactorY = 1 / 525.f * 640.f / dims[0];
        centerX = ((float)dims[0] - 1.f) / 2.f;
        centerY = ((float)dims[1] - 1.f) / 2.f;
    }

    pcl::PointXYZ KinectDataConverter::ConvertOnePoint(float x, float y, float depthValue, cv::Size frameSize)
    {
        float centerX, centerY;
        float scaleFactorX, scaleFactorY;

        ComputeCameraIntrinsics(frameSize, centerX, centerY, scaleFactorX, scaleFactorY);

        pcl::PointXYZ pt;
        pt.x = (static_cast<float>(x) - centerX) * scaleFactorX * depthValue;
        pt.y = (centerY - static_cast<float>(y)) * scaleFactorY * depthValue;
        pt.z = depthValue;
        return pt;
    }

}


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Converter/KinectDataConverter.h
================================================
#ifndef KINECTDATACONVERTER_H
#define KINECTDATACONVERTER_H

#include <Converter/IDataConverter.h>

namespace hpe
{
    /**
     \class	KinectDataConverter
    
     \brief	Converts RGB-D pair to a point cloud. Work only for a kinect sensor.
    
     \author	Sergey
     \date	8/11/2015
     */

    class KinectDataConverter : public IDataConverter
    {
        public:
            KinectDataConverter();
            pcl::PointCloud<pcl::PointXYZRGBA>::Ptr DepthRGBToPointCloud(cv::Mat &depth, cv::Mat &bgr) override;
            pcl::PointXYZ ConvertOnePoint(float x, float y, float depthValue, cv::Size frameSize);

        protected:
            virtual void ComputeCameraIntrinsics(cv::Size &imageSize, float &centerX, float &centerY, float &scaleFactorX, float &scaleFactorY);
    };
}

#endif // KINECTDATACONVERTER_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/DataFilter/IDataFilter.h
================================================
#ifndef IDATAFILTER_H
#define IDATAFILTER_H

#include "Interface/IInterface.h"

namespace hpe
{
    template <typename DataType>
    class DataFilter : public IInterface
    {
        public:
            virtual DataType Filter(DataType &input) = 0;
    };
}

#endif // IDATAFILTER_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/CloudXYZRGBA.h
================================================
#pragma once

#ifndef CLOUDXYZRGBA_H
#define CLOUDXYZRGBA_H

#include <DataObject/IDataObject.h>

#include <pcl/point_types.h>
#include <pcl/point_cloud.h>

namespace hpe
{
    class CloudXYZRGBA : public IDataObject
    {
        public:
            typedef std::shared_ptr<CloudXYZRGBA> Ptr;

            CloudXYZRGBA()
            {
            }

            CloudXYZRGBA(bool create)
            {
                if (create)
                {
                    cloud = pcl::PointCloud<pcl::PointXYZRGBA>::Ptr(new pcl::PointCloud<pcl::PointXYZRGBA>);
                }
            }

            pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud;
    };
}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/HeadPoseInfo.h
================================================
#ifndef HEADPOSEINFO_H
#define HEADPOSEINFO_H

#include <DataObject/IDataObject.h>

namespace hpe
{
    class HeadPoseInformation : public IDataObject
    {
        public:
            typedef std::shared_ptr<HeadPoseInformation> Ptr;

            HeadPoseInformation()
            {
                Yaw = 0;
                Tilt = 0;
                Roll = 0;
                WorldX = 0;
                WorldY = 0;
                WorldZ = 0;
                DepthFrameX = 0;
                DepthFrameY = 0;
                HasHeadInfo = false;
            }

            double Yaw;
            double Tilt;
            double Roll;
            double WorldX;
            double WorldY;
            double WorldZ;
            double DepthFrameX;
            double DepthFrameY;
            bool HasHeadInfo;
    };
}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/IDataObject.h
================================================
#pragma once

#ifndef IDATAOBJECT_H
#define IDATAOBJECT_H

#include <Interface/IInterface.h>

#include <memory>

namespace hpe
{
    /**
     \class	IDataObject
    
     \brief	Interface to store the objects to put into IDataStorage.
			See subclasses for examples.
    
     \author	Sergey
     \date	8/11/2015
     */

    class IDataObject : public IInterface
    {
        public:
            typedef std::shared_ptr<IDataObject> Ptr;
    };
}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/IDataStorage.h
================================================
#pragma once

#ifndef IDATASTORAGE_H
#define IDATASTORAGE_H

#include <Interface/IInterface.h>
#include <DataObject/IDataObject.h>
#include <Exception/HPEException.h>

#include <string>

namespace hpe
{
    /**
     \class	IDataStorage
    
     \brief	One of the key classes to organize between communications processors. 
			Basically is a key-value storage. 
    
     \author	Sergey
     \date	8/11/2015
     */

    class IDataStorage : public IInterface
    {
        public:
            typedef std::shared_ptr<IDataStorage> Ptr;

            /**
             \fn	virtual void IDataStorage::Set(std::string key, IDataObject::Ptr object) = 0;
            
             \brief	Add object into storage with key
            
             \author	Sergey
             \date	8/11/2015
            
             \param	key   	Key
             \param	object	Object to add. The object should be contained in IDataObject
             */

            virtual void Set(std::string key, IDataObject::Ptr object) = 0;
            virtual IDataObject::Ptr Get(std::string key) = 0;
            virtual void Remove(std::string key) = 0;

            template<class T>
            std::shared_ptr<T> GetAndCast(std::string key)
            {
                IDataObject::Ptr obj = Get(key);
                return std::dynamic_pointer_cast<T>(obj);
            }

            template<class T>
            std::shared_ptr<T> GetAndCastNotNull(std::string key, std::string message = "Got nullptr from storage")
            {
                std::shared_ptr<T> ptr = GetAndCast<T>(key);
                if (ptr.get() == nullptr)
                {
                    throw HPEException(message);
                }
                return ptr;
            }

    };

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/LandmarksObject.h
================================================
#pragma once

#ifndef LANDMARKSOBJECT_H
#define LANDMARKSOBJECT_H

#include <DataObject/IDataObject.h>

#include <Landmarks.h>

namespace hpe
{
    template <class PointType>
    class LandmarksObject : public IDataObject
    {
        public:
            typedef std::shared_ptr<LandmarksObject> Ptr;

            typename Common<PointType>::Landmarks landmarks;
    };
}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/MapDataStorage.cpp
================================================
#include "MapDataStorage.h"

namespace hpe
{
    void MapDataStorage::Set(std::string key, IDataObject::Ptr object)
    {
        m_storage[key] = object;
    }

    IDataObject::Ptr MapDataStorage::Get(std::string key)
    {
        return m_storage[key];
    }

    void MapDataStorage::Remove(std::string key)
    {
        auto it = m_storage.find(key);
        if (it != m_storage.end())
        {
            m_storage.erase(it);
        }
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/MapDataStorage.h
================================================
#pragma once

#ifndef MAPDATASTORAGE_H
#define MAPDATASTORAGE_H

#include <DataObject/IDataStorage.h>
#include <map>

namespace hpe
{

    class MapDataStorage : public IDataStorage
    {
        public:
            void Set(std::string key, IDataObject::Ptr object);
            IDataObject::Ptr Get(std::string key);
            void Remove(std::string key);
        private:
            std::map<std::string, IDataObject::Ptr> m_storage;
    };

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/RawFrames.h
================================================
#pragma once

#ifndef RAWFRAMES_H
#define RAWFRAMES_H

#include <DataObject/IDataObject.h>

#include <opencv2/opencv.hpp>

namespace hpe
{
    class RawFrames : public IDataObject
    {
        public:
            typedef std::shared_ptr<RawFrames> Ptr;

            cv::Mat colorFrame;
            cv::Mat depthFrame;
    };
}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/DepthDetector.cpp
================================================
#include "DepthDetector.h"

#include <boost/math/special_functions/fpclassify.hpp>

namespace hpe
{

    DepthDetector::DepthDetector(std::string dataFolder)
    {
        Init(dataFolder);
    }

    DepthDetector::~DepthDetector(void)
    {
    }

    hpe::headPoseInfo DepthDetector::Detect(cv::Mat depthFrame)
    {
        cv::Mat converted(depthFrame.rows, depthFrame.cols, depthFrame.type());

        for (int y = 0; y < depthFrame.rows; ++y)
        {
            for (int x = 0; x < depthFrame.cols; ++x)
            {
                float depthValue = depthFrame.at<float>(y, x);

                if (depthValue > 1.5 || depthValue == 0.0f || boost::math::isnan(depthValue))
                {
                    depthValue = 0;
                }
                else
                {
                    depthValue = depthValue * 1000;
                }

                converted.at<float>(y, x) = depthValue;
            }
        }

        headPoseInfo info = estimateHeadAngles(converted, m_cascade, m_paramList);
        return info;
    }

    void DepthDetector::Init(std::string dataFolder)
    {
        std::string configFileName = dataFolder + "/config.txt";
        loadConfig(configFileName, &m_paramList);

        std::string modelsDir = dataFolder + "/models/";
        for (int i = 0; i < 5; i++)
        {
            m_cascade.push_back(readTree(modelsDir, i + 1));
        }
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/DepthDetector.h
================================================
#pragma once

#ifndef DEPTHDETECTOR_H
#define DEPTHDETECTOR_H

#include <opencv2/opencv.hpp>

#include "localFunctions.h"
#include "Tree.h"

namespace hpe
{
    class DepthDetector
    {
        public:
            DepthDetector(std::string dataFolder);
            ~DepthDetector(void);

            headPoseInfo Detect(cv::Mat depthFrame);
        private:
            void Init(std::string dataFolder);

            paramList m_paramList;
            std::vector<Tree> m_cascade;
    };
}

#endif


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/LeafNode.cpp
================================================
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "LeafNode.h"

using namespace cv;
using namespace std;
using std::vector;

namespace hpe
{


    void evaluatePackedTree(Mat patchInt, Mat maskInt, Mat treeMat, Mat treeIdxMap, int initDepth, const cv::Rect roi, LeafNode *leaf)
    {

        int leafDim = treeMat.cols;//(int*) mxGetDimensions(input[2]);
        leaf->mean.create(1, 6, CV_64FC1);
        int node = initDepth;
        double pnode = (int)treeMat.at<double>(node, 1);
        int incr = 0;

        int xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;

        while (pnode == -1) {
            xa1 = roi.x + (int)treeMat.at<double>(node, 2);
            ya1 = roi.y + (int)treeMat.at<double>(node, 3);
            xa2 = xa1 + (int)treeMat.at<double>(node, 6);
            ya2 = ya1 + (int)treeMat.at<double>(node, 7);
            xb1 = roi.x + (int)treeMat.at<double>(node, 4);
            yb1 = roi.y + (int)treeMat.at<double>(node, 5);
            xb2 = xb1 + (int)treeMat.at<double>(node, 8);
            yb2 = yb1 + (int)treeMat.at<double>(node, 9);

            double numrA = patchInt.at<double>(ya2, xa2) - patchInt.at<double>(ya2, xa1) - patchInt.at<double>(ya1, xa2) + patchInt.at<double>(ya1, xa1);
            double numA = maskInt.at<double>(ya2, xa2) - maskInt.at<double>(ya2, xa1) - maskInt.at<double>(ya1, xa2) + maskInt.at<double>(ya1, xa1);

            double numrB = patchInt.at<double>(yb2, xb2) - patchInt.at<double>(yb2, xb1) - patchInt.at<double>(yb1, xb2) + patchInt.at<double>(yb1, xb1);
            double numB = maskInt.at<double>(yb2, xb2) - maskInt.at<double>(yb2, xb1) - maskInt.at<double>(yb1, xb2) + maskInt.at<double>(yb1, xb1);

            double mxA = (numA > 1) ? numA : 1;
            double mxB = (numB > 1) ? numB : 1;

            double testVal = numrA / mxA - numrB / mxB;
            int test = (testVal >= treeMat.at<double>(node, 11)) ? 1 : 0;

            node = (int)treeMat.at<double>(node, 0) - 1;
            incr = node + test + 1;
            node = (int)(treeIdxMap.at<double>(node + incr, 0) - 1);
            pnode = (int)treeMat.at<double>(node, 1);
        }

        /*for(int i=0; i< leafDim; i++)
        {
            *out = treeMat.at<double>(node, i);
            out++;
        }*/

        leaf->pfg = treeMat.at<double>(node, 2);
        leaf->trace = treeMat.at<double>(node, 3);
        //cout << treeMat.at<double>(node, 4) << endl;
        leaf->mean = (Mat_<double>(1, 6) << treeMat.at<double>(node, 4),
                      treeMat.at<double>(node, 5),
                      treeMat.at<double>(node, 6),
                      treeMat.at<double>(node, 7),
                      treeMat.at<double>(node, 8),
                      treeMat.at<double>(node, 9));
        /*leaf->mean.at<double>(0) = treeMat.at<double>(node, 4);
        leaf->mean.at<double>(1) = treeMat.at<double>(node, 5);
        leaf->mean.at<double>(2) = treeMat.at<double>(node, 6);
        leaf->mean.at<double>(3) = treeMat.at<double>(node, 7);
        leaf->mean.at<double>(4) = treeMat.at<double>(node, 8);
        leaf->mean.at<double>(5) = treeMat.at<double>(node, 9);*/

        //return leafPtr;
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/LeafNode.h
================================================
#ifndef LEAFNODE_H
#define LEAFNODE_H

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;

namespace hpe
{

    class LeafNode {

        public:

            LeafNode() { }
            ~LeafNode() {
                mean.release();
            }

            // Probability of belonging to head region
            double pfg;
            // mean vector
            cv::Mat mean;
            // trace of the covariance matrix
            double trace;

    };

//LeafNode* evaluatePackedTree(Mat patchInt, Mat maskInt, Mat treeMat, Mat treeIdxMap, int initDepth, const cv::Rect roi);
    void evaluatePackedTree(Mat patchInt, Mat maskInt, Mat treeMat, Mat treeIdxMap, int initDepth, const cv::Rect roi, LeafNode *leaf);

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/Tree.cpp
================================================
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "Tree.h"
#include "csvMat.h"

using namespace cv;
using namespace std;
using std::vector;

#include <fstream>

namespace hpe
{

    Tree readTree(string csvRootName, int treeIdx)
    {
        cout << "Reading tree no. " << treeIdx << " from: " << csvRootName << endl;
        string treeIdxStr;
        ostringstream convert;
        convert << treeIdx;
        treeIdxStr = convert.str();
        string specsFileName = csvRootName + "tree00" + treeIdxStr + "_specs.csv";
        Mat specsMat;
        specsMat.create(1, 6, CV_64FC1);
        specsMat = readCSVMat(specsFileName, 1, 6);

        Tree t;
        t.treeMat.create(int(specsMat.at<double>(0)), int(specsMat.at<double>(1)), CV_64FC1);
        t.idxMap.create(int(specsMat.at<double>(2)), 1, CV_64FC1);

        string matFileName = csvRootName + "tree00" + treeIdxStr + "_Mat.csv";
        string idxMapFileName = csvRootName + "tree00" + treeIdxStr + "_IdxMap.csv";

        t.treeMat = readCSVMat(matFileName, int(specsMat.at<double>(0)), int(specsMat.at<double>(1)));
        t.idxMap = readCSVMat(idxMapFileName, int(specsMat.at<double>(2)), 1);

        return t;
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/Tree.h
================================================
#pragma once
#ifndef TREE_H
#define TREE_H

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;

namespace hpe
{

    class Tree {

        public:

            Tree() { }
            ~Tree() { }

            Mat treeMat, idxMap;
    };

    Tree readTree(string csvRootName, int treeIdx);

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/csvMat.cpp
================================================
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "csvMat.h"

using namespace cv;
using namespace std;
using std::vector;

#include <fstream>

namespace hpe
{

    Mat readCSVMat(string csvFrameName, int lin, int col)
    {
        Mat output(lin, col, CV_64FC1);
        ifstream inFile(csvFrameName);
        string line;
        int linenum = 0;
        while (getline(inFile, line))
        {
            linenum++;
            //cout << "\nLine #" << linenum << ":" << endl;
            istringstream linestream(line);
            string item;
            int itemnum = 0;
            while (getline(linestream, item, ','))
            {
                itemnum++;
                //cout << "Item #" << itemnum << ": " << item << endl;
                double temp = (double)atof(item.c_str());
                output.at<double>(linenum - 1, itemnum - 1) = (double)temp;
            }
        }
        return output;
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/csvMat.h
================================================
#pragma once
#ifndef CSVMAT_H
#define CSVMAT_H

#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stdint.h>
#include "opencv2/core/core.hpp"

using namespace std;
using namespace cv;

namespace hpe
{

    Mat readCSVMat(string csvFrameName, int lin, int col);

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/localFunctions.cpp
================================================
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stdint.h>
#include <opencv2/opencv.hpp>
#include "localFunctions.h"
#include <fstream>
#include <opencv2/imgproc/imgproc.hpp>
#include "Tree.h"
#include "LeafNode.h"

using namespace std;
using namespace cv;

namespace hpe
{

    void loadConfig(std::string filename, paramList *p, bool verbose)
    {
        ifstream in(filename);
        string dummy;

        if (in.is_open()) {

            in >> dummy;
            in >> p->maskThreshold;

            in >> dummy;
            in >> p->stride;

            in >> dummy;
            in >> p->patchSize;

            in >> dummy;
            in >> p->headPatchProb;

            in >> dummy;
            in >> p->headDiameter;

            in >> dummy;
            in >> p->headPatchDistTh;

            in >> dummy;
            in >> p->minVotes;

            in >> dummy;
            in >> p->yawTrace;

            in >> dummy;
            in >> p->tiltTrace;

            in >> dummy;
            in >> p->ytDiameter;

        }
        else {
            cerr << "File not found " << filename << endl;
        }
        in.close();

        if (verbose)
        {
            cout << endl << "------------------------------------" << endl;
            cout << "Parameter List:       " << endl << endl;
            cout << "maskThreshold:            " << p->maskThreshold << endl;
            cout << "stride:			  " << p->stride << endl;
            cout << "patchSize:                " << p->patchSize << endl;
            cout << "headPatchProb:            " << p->headPatchProb << endl;
            cout << "headDiameter:             " << p->headDiameter << endl;
            cout << "headPatchDistTh:          " << p->headPatchDistTh << endl;
            cout << "minNoVotes:               " << p->minVotes << endl;
            cout << "yawTrace:                 " << p->yawTrace << endl;
            cout << "tiltTrace:                " << p->tiltTrace << endl;
            cout << "yawTiltDiameter:          " << p->ytDiameter << endl;

            cout << endl << "------------------------------------" << endl << endl;
        }
    }

    Rect getBoundingBox(const Mat &im3D, paramList p) {

        Rect bbox;
        int min_x = im3D.cols;
        int min_y = im3D.rows;
        int max_x = 0;
        int max_y = 0;
        int p_width = p.patchSize;
        int p_height = p.patchSize;

        for (int y = 0; y < im3D.rows; y++)
        {
            const double *Mi = im3D.ptr<double>(y);
            for (int x = 0; x < im3D.cols; x++) {

                if (Mi[x] > 0) {

                    min_x = MIN(min_x, x);
                    min_y = MIN(min_y, y);
                    max_x = MAX(max_x, x);
                    max_y = MAX(max_y, y);
                }

            }
        }

        int new_w = max_x - min_x;
        int new_h = max_y - min_y;

        bbox.x = MIN(im3D.cols - 1, MAX(0 , min_x));
        bbox.y = MIN(im3D.rows - 1, MAX(0 , min_y));

        //int new_w = max_x - min_x + p_width;
        //int new_h = max_y - min_y + p_height;

        //bbox.x = MIN( im3D.cols-1, MAX( 0 , min_x - p_width/2 ) );
        //bbox.y = MIN( im3D.rows-1, MAX( 0 , min_y - p_height/2) );

        bbox.width  = MAX(0, MIN(new_w, im3D.cols - bbox.x));
        bbox.height = MAX(0, MIN(new_h, im3D.rows - bbox.y));

        return bbox;
    }

    double computeNorm(vector<double> vec1, vector<double> vec2)
    {
        double result = 0;
        int dim = vec1.size();
        vector<double> diff(dim);
        double sumSq = 0;
        for (int i = 0; i < dim; i++)
        {
            diff[i] = vec1[i] - vec2[i];
            sumSq += pow(diff[i], 2);
        }
        result = sqrt(sumSq);
        return result;
    }

    double computeMean(vector<double> vec)
    {
        double sum = 0;
        for (int k = 0; k < vec.size(); k++)
        {
            sum += vec[k];
        }
        return sum / vec.size();
    }

    Mat meanShift(Mat dataPts, double bandWidth, int *maxClustPointer)
    {
        *maxClustPointer = -1;
        int biggestClusterSize = 0;
        int numDim = dataPts.cols;
        int numPts = dataPts.rows;
        int numClust = -1;
        double bandSq = bandWidth * bandWidth;
        std::vector<int> initPtInds(numPts);
        for (int k = 0; k < initPtInds.size(); k++)
            initPtInds[k] = k;

        double stopThresh = 1e-3 * bandWidth;

        Mat clustCent(0, numDim, CV_64FC1);

        vector<bool> beenVisitedFlag(numPts);
        int numInitPts = numPts;
        //vector<int> clusterVotes(numPts);

        while (numInitPts > 0)
        {
            int tempInd = (int)std::ceil((float)(numInitPts - 1) * std::rand() / RAND_MAX);
            double stInd = (double)initPtInds[tempInd];

            std::vector<double> myMean(numDim);
            for (int i = 0; i < numDim; i++)
            {
                myMean[i] = (double)dataPts.at<double>(stInd, i);
            }

            vector<int> thisClusterVotes(numPts);

            while (1)
            {
                vector<double> sqDistToAll(numPts);
                for (int i = 0; i < numPts; i++)
                {
                    double result = 0;
                    for (int j = 0; j < numDim; j++)
                    {
                        double diff = (double)dataPts.at<double>(i, j) - myMean[j];
                        result += pow(diff, 2);
                    }
                    sqDistToAll[i] = result;
                }
                vector<bool> inInds(numPts);
                for (int i = 0; i < numPts; i++)
                {
                    inInds[i] = sqDistToAll[i] < bandSq;
                    if (inInds[i] == true)
                    {
                        thisClusterVotes[i]++;
                    }
                }

                int countTrues = count_if(inInds.begin(), inInds.end(), [](bool b) {
                    return b == true;
                });
                vector<double> myOldMean = myMean;
                cv::Mat tempData(countTrues, numDim, CV_64FC1);
                int localIdx = 0;
                for (int i = 0; i < inInds.size(); i++)
                {
                    if (inInds[i] == true)
                    {
                        for (int j = 0; j < numDim; j++)
                        {
                            tempData.at<double>(localIdx, j) = (double)dataPts.at<double>(i, j);
                        }
                        localIdx++;
                        beenVisitedFlag[i] = true;
                    }
                }
                Mat myMeanMat;
				cv::reduce(tempData, myMeanMat, 0, CV_REDUCE_AVG);
                myMeanMat.copyTo(myMean);

                // compute the 2-norm of the difference-between-means vector
                double meanNorm = computeNorm(myOldMean, myMean);

                if (meanNorm < stopThresh)
                {
                    int mergeWith = -1;
                    for (int cn = 0; cn <= numClust; cn++)
                    {
                        vector<double> localClustCent(numDim);
                        clustCent.row(cn).copyTo(localClustCent);
                        double distToOther = computeNorm(myMean, localClustCent);

                        if (distToOther < bandWidth / 2)
                        {
                            mergeWith = cn;
                            break;
                        }
                    }

                    if (mergeWith >= 0)
                    {
                        Mat localMat = 0.5 * (myMeanMat + clustCent.row(mergeWith));
                        localMat.copyTo(clustCent.row(mergeWith));
                    }
                    else
                    {
                        numClust++;
                        clustCent.push_back(myMeanMat);
                        if (tempData.rows > biggestClusterSize)
                        {
                            biggestClusterSize = tempData.rows;
                            *maxClustPointer = *maxClustPointer + 1;
                        }
                        //myMeanMat.copyTo(clustCent.row(numClust));
                    }
                    break;
                }
            }

            initPtInds.clear();
            for (int i = 0; i < beenVisitedFlag.size(); i++)
            {
                if (beenVisitedFlag[i] == false)
                {
                    initPtInds.push_back(i);
                }
            }
            numInitPts = initPtInds.size();
        }
        return clustCent;
    }

    headPoseInfo estimateHeadAngles(Mat depthFrame, vector<Tree> cascade, paramList p)
    {
        headPoseInfo eAngles;
        eAngles.x = 0;
        eAngles.y = 0;
        eAngles.tilt = -100;
        eAngles.yaw = -100;

        int p_width = p.patchSize;
        int p_height = p.patchSize;
        Rect bbox = getBoundingBox(depthFrame, p);

        //integral image of the depth frame
        int rows = depthFrame.rows;
        int cols = depthFrame.cols;
        Mat depthInt(rows + 1, cols + 1, CV_64FC1);
        integral(depthFrame, depthInt);

        //mask
        depthFrame.convertTo(depthFrame, CV_32FC1);
        Mat mask(rows, cols, CV_32FC1);
        mask.setTo(0);
        cv::threshold(depthFrame, mask, p.maskThreshold, 1, THRESH_BINARY);

        //integral image of the mask
        Mat maskInt(rows + 1, cols + 1, CV_64FC1);
        maskInt.setTo(0);
        integral(mask, maskInt);

        //defines the test patch
        Rect roi = Rect(0, 0, p_width, p_height);

        int min_no_pixels = p_width * p_height / 10;

        //vector<LeafNode*> leaves;
        LeafNode bufferLeaf;

        //process each patch
        int startX = std::max(2, bbox.x + 1 - p_width / 2 + 1);
        int endX = std::min(bbox.x + bbox.width - p_width / 2 + 1, maskInt.cols - p_width);
        int startY = std::max(2, bbox.y + 1 - p_height / 2 + 1);
        int endY = std::min(bbox.y + bbox.height - p_height / 2 + 1, maskInt.rows - p_height);
        vector<double> headPatchIdxX, headPatchIdxY;

        for (roi.y = startY; roi.y <= endY; roi.y += p.stride)
        {
            for (roi.x = startX; roi.x <= endX; roi.x += p.stride)
            {
                int x0 = roi.x;
                int y0 = roi.y;
                int x1 = x0 + p_width - 1;
                int y1 = y0 + p_height - 1;

                //discard if the patch is filled with data for less than 10%
                double areaSum = maskInt.at<double>(y1, x1) - maskInt.at<double>(y1, x0 - 1) - maskInt.at<double>(y0 - 1, x1) + maskInt.at<double>(y0, x0);
                if (areaSum / (p_width * p_height) <= 0.1)
                    continue;

                evaluatePackedTree(depthInt, maskInt, cascade[0].treeMat, cascade[0].idxMap, 0, roi, &bufferLeaf);

                // store only patches that are almost certain to belong to the head
                if (bufferLeaf.pfg > p.headPatchProb)
                {
                    headPatchIdxX.push_back((double)x0);
                    headPatchIdxY.push_back((double)y0);
                }
            }
        }

        if (headPatchIdxX.size() > 0)
        {
            Mat dataPtsX(headPatchIdxX);
            Mat dataPtsY(headPatchIdxY);
            Mat dataPts;
            hconcat(dataPtsX, dataPtsY, dataPts);

            int maxClustIdx = -1; // initialize the index of the biggest cluster (in case there are more than 1, it is useful to know which is the biggest)
            Mat clustCent = meanShift(dataPts, p.headDiameter, &maxClustIdx);
            vector<double> clustCentVec(dataPts.cols);
            clustCent.row(maxClustIdx).copyTo(clustCentVec);

            // once the center of the patches that "think" they belong to the head has been found
            // it's time to call the X and Y offset trees that will vote for the head center
            // and the Yaw/Tilt trees for the yaw/tilt predictions

            Mat votes(0, 8, CV_64FC1); // offsetX, offsetY, offsetZ(not used), yaw, tilt, roll(not used), traceYaw, traceTilt
            Mat dummyVote(1, 8, CV_64FC1);
            Mat headPatchDataMat(0, 2, CV_64FC1);
            Mat headPatchCenterAux(1, 2, CV_64FC1);

            for (roi.y = startY; roi.y <= endY; roi.y += p.stride)
            {
                for (roi.x = startX; roi.x <= endX; roi.x += p.stride)
                {
                    vector<double> currPoint(clustCentVec.size());
                    currPoint[0] = roi.x;
                    currPoint[1] = roi.y;

                    int x0 = roi.x;
                    int y0 = roi.y;
                    int x1 = x0 + p_width - 1;
                    int y1 = y0 + p_height - 1;

                    double areaSum = maskInt.at<double>(y1, x1) - maskInt.at<double>(y1, x0 - 1) - maskInt.at<double>(y0 - 1, x1) + maskInt.at<double>(y0, x0);
                    double localNorm = computeNorm(clustCentVec, currPoint);

                    if ((areaSum / (p_width * p_height) > 0.1) & (localNorm <= p.headPatchDistTh))
                    {
                        headPatchCenterAux.at<double>(0, 0) = (double)(x0 + p.patchSize / 2);
                        headPatchCenterAux.at<double>(0, 1) = (double)(y0 + p.patchSize / 2);
                        headPatchDataMat.push_back(headPatchCenterAux);
                        // offset on X
                        evaluatePackedTree(depthInt, maskInt, cascade[1].treeMat, cascade[1].idxMap, 0, roi, &bufferLeaf);
                        dummyVote.at<double>(0) = x0 + p.patchSize / 2 - bufferLeaf.mean.at<double>(0);
                        // offset on Y
                        evaluatePackedTree(depthInt, maskInt, cascade[2].treeMat, cascade[2].idxMap, 0, roi, &bufferLeaf);
                        dummyVote.at<double>(1) = y0 + p.patchSize / 2 - bufferLeaf.mean.at<double>(1);
                        dummyVote.at<double>(2) = 0;
                        // Yaw
                        evaluatePackedTree(depthInt, maskInt, cascade[3].treeMat, cascade[3].idxMap, 0, roi, &bufferLeaf);
                        dummyVote.at<double>(3) = bufferLeaf.mean.at<double>(3);
                        dummyVote.at<double>(5) = 0;
                        dummyVote.at<double>(6) = bufferLeaf.trace;
                        // Tilt
                        evaluatePackedTree(depthInt, maskInt, cascade[4].treeMat, cascade[4].idxMap, 0, roi, &bufferLeaf);
                        dummyVote.at<double>(4) = bufferLeaf.mean.at<double>(4);
                        dummyVote.at<double>(7) = bufferLeaf.trace;
                        votes.push_back(dummyVote);
                    }
                }
            }

            vector<double> mnHC(2);
            mnHC[0] = 0;
            mnHC[1] = 0;

            Mat votesFin(8, votes.rows, CV_64FC1);
            transpose(votes, votesFin);

            vector<double> offsetXVec(votesFin.cols), offsetYVec(votesFin.cols), predYawVec(votesFin.cols);
            vector<double> predTiltVec(votesFin.cols), traceYawVec(votesFin.cols), traceTiltVec(votesFin.cols);
            votesFin.row(0).copyTo(offsetXVec);
            votesFin.row(1).copyTo(offsetYVec);
            votesFin.row(3).copyTo(predYawVec);
            votesFin.row(4).copyTo(predTiltVec);
            votesFin.row(6).copyTo(traceYawVec);
            votesFin.row(7).copyTo(traceTiltVec);

            if (offsetXVec.size() > 0)
            {
                mnHC[0] = computeMean(offsetXVec);
                mnHC[1] = computeMean(offsetYVec);
                eAngles.x = mnHC[0];
                eAngles.y = mnHC[1];

                vector<double> distHeadCenter(headPatchDataMat.rows);
                vector<double> distHeadCenterIdx(headPatchDataMat.rows);
                vector<double> headPatchDataLocal(2);
                for (int k = 0; k < headPatchDataMat.rows; k++)
                {
                    headPatchDataMat.row(k).copyTo(headPatchDataLocal);
                    distHeadCenter[k] = computeNorm(headPatchDataLocal, mnHC);
                    distHeadCenterIdx[k] = k;
                }
                std::sort(distHeadCenterIdx.begin(), distHeadCenterIdx.end(), [&distHeadCenter](size_t i1, size_t i2) {
                    return distHeadCenter[i1] < distHeadCenter[i2];
                });
                vector<int> headCenterInd(offsetXVec.size());
                headCenterInd.assign(offsetXVec.size(), 0);
                if (offsetXVec.size() > p.minVotes)
                {
                    for (int k = 0; k < p.minVotes; k++)
                    {
                        headCenterInd[(int)distHeadCenterIdx[k]] = 1;
                    }
                }
                else
                {
                    headCenterInd.assign(offsetXVec.size(), 1);
                }

                vector<int> traceInd(offsetXVec.size());
                traceInd.assign(offsetXVec.size(), 0);

                for (int k = 0; k < offsetXVec.size(); k++)
                {
                    if ((traceYawVec[k] + traceTiltVec[k]) / 2 < p.yawTrace)
                    {
                        traceInd[k] = 1;
                    }
                }

                vector<int> allInds(traceInd.size());
                Mat yawTiltPoints(0, 2, CV_64FC1);
                Mat yawTiltDummy(1, 2, CV_64FC1);

                for (int k = 0; k < traceInd.size(); k++)
                {
                    allInds[k] = traceInd[k] * headCenterInd[k];
                    if (allInds[k] == 1)
                    {
                        yawTiltDummy.at<double>(0) = predYawVec[k];
                        yawTiltDummy.at<double>(1) = predTiltVec[k];
                        yawTiltPoints.push_back(yawTiltDummy);
                    }
                }
                //std::transform(headCenterInd.begin() + 1, headCenterInd.end(), traceInd.begin()+ 1, std::multiplies<int>());

                int maxClustIdx = -1;
                Mat clustCent = meanShift(yawTiltPoints, p.ytDiameter, &maxClustIdx);
                if (maxClustIdx != -1 && maxClustIdx < clustCent.rows)
                {
                    eAngles.yaw = clustCent.at<double>(maxClustIdx, 0);
                    eAngles.tilt = clustCent.at<double>(maxClustIdx, 1);
                }

                //clustCent.row(maxClustIdx).copyTo(eAngles);
            }
        }

        return eAngles;
    }

}


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/localFunctions.h
================================================
#ifndef LOCALFUNCTIONS_H
#define LOCALFUNCTIONS_H

#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stdint.h>
#include "opencv2/core/core.hpp"
#include "Tree.h"

using namespace std;
using namespace cv;

namespace hpe
{

    struct paramList
    {
        double maskThreshold;
        int stride;
        int patchSize;
        double headPatchProb;
        double headDiameter;
        double headPatchDistTh;
        double minVotes;
        double yawTrace;
        double tiltTrace;
        double ytDiameter;
    };

    struct headPoseInfo
    {
        double x, y, yaw, tilt;
    };

    void loadConfig(std::string filename, paramList *p, bool verbose = false);
    Rect getBoundingBox(const Mat &im3D, paramList p);
    double computeNorm(vector<double> vec1, vector<double> vec2);
    double computeMean(vector<double> vec);
    headPoseInfo estimateHeadAngles(Mat depthFrame, vector<Tree> cascade, paramList p);

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Exception/HPEException.cpp
================================================
#include "HPEException.h"

HPEException::HPEException(std::string message)
    : m_message(message)
{

}

const char *HPEException::what()
{
    return m_message.c_str();
}


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Exception/HPEException.h
================================================
#ifndef HPEEXCEPTION_H
#define HPEEXCEPTION_H

#include <stdexcept>

class HPEException : public std::exception
{
    public:
        HPEException(std::string message);
        virtual const char *what();

    private:
        std::string m_message;
};

#endif // HPEEXCEPTION_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/FacialExpressions/ferLocalFunctions.cpp
================================================
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stdint.h>
#include "opencv2/core/core.hpp"
#include "ferLocalFunctions.h"
#include <fstream>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <Windows.h>
#include <map>
#include <boost/filesystem.hpp>

namespace fer
{

    using namespace std;
    using namespace cv;

    std::string to_string(int val)
    {
        std::stringstream str;
        str << val;
        return str.str();
    }

    vector<string> get_all_files_names_within_folder(string folder)
    {
        vector<string> names;

        namespace fs = boost::filesystem;
        fs::directory_iterator end_iter;
        if (fs::exists(folder) && fs::is_directory(folder))
        {
            for (fs::directory_iterator dir_iter(folder) ; dir_iter != end_iter ; ++dir_iter)
            {
                if (fs::is_regular_file(dir_iter->status()))
                {
                }
            }
        }

        return names;
    }


    Mat RV_readCSVMat(string csvFrameName, int lin, int col)
    {
        Mat output(lin, col, CV_64FC1);
        ifstream inFile(csvFrameName);
        string line;
        int linenum = 0;
        while (getline(inFile, line))
        {
            linenum++;
            //cout << "\nLine #" << linenum << ":" << endl;
            istringstream linestream(line);
            string item;
            int itemnum = 0;
            while (getline(linestream, item, ','))
            {
                itemnum++;
                //cout << "Item #" << itemnum << ": " << item << endl;
                double temp = (double)atof(item.c_str());
                output.at<double>(linenum - 1, itemnum - 1) = (double)temp;
            }
        }
        return output;
    }

    void RV_readParamList(const string foldername, paramList *p)
    {
        cout << "Reading params from: " << foldername << "...";
        ifstream in(foldername + "config.txt");
        string dummy;

        if (in.is_open()) {

            in >> dummy;
            in >> p->d;

            in >> dummy;
            in >> p->patchSize;

            in >> dummy;
            in >> p->stride;

            in >> dummy;
            in >> p->featSize;

            in >> dummy;
            in >> p->noPatches;

            in >> dummy;
            in >> p->noChannels;

            in >> dummy;
            in >> p->noTrees;

        }
        else {
            cerr << "File not found " << foldername + "config.txt" << endl;
            exit(-1);
        }
        in.close();

        Mat dummyMat(p->d, 16, CV_64FC1);
        dummyMat.setTo(0);
        for (int i = 0; i < p->noPatches; i++)
        {
            p->patchFeats.push_back(dummyMat);
        }

        Mat paramsPatchCoords = RV_readCSVMat(foldername + "paramsPatchCoords.csv", p->noPatches, 2);
        p->patchCoords = paramsPatchCoords;

        for (int i = 0; i < p->noPatches; i++)
        {
            // rectangle coordinates are imported from Matlab as they are, which means they obey Matlab indexing (starting from 1)
            // this will be taken care of explicitly at feature computation stage ...
            Mat patchFeatsAux = RV_readCSVMat(foldername + "patchFeats/patchFeats_" + to_string(i + 1) + ".csv", p->d, 16);
            Mat patchFeatsAuxInt(patchFeatsAux.rows, patchFeatsAux.cols, CV_8UC1);
            patchFeatsAux.convertTo(patchFeatsAuxInt, CV_8UC1);
            p->patchFeats[i] = patchFeatsAuxInt;
        }

        cout << "done!" << endl;
        cout << endl << "------------------------------------" << endl;
        cout << "Parameter List:" << endl << endl;
        cout << "d:             " << p->d << endl;
        cout << "patchSize:     " << p->patchSize << endl;
        cout << "stride:        " << p->stride << endl;
        cout << "featSize:      " << p->featSize << endl;
        cout << "noPatches:     " << p->noPatches << endl;
        cout << "noChannels:    " << p->noChannels << endl;
        cout << endl << "------------------------------------" << endl << endl;
    }

    vector<vector<randomTree>> RV_readAllForests(string forestDir, paramList params)
    {
        vector<vector<randomTree>> allForests(params.noPatches, vector<randomTree>(params.noTrees));
        cout << "Reading forests from: " << forestDir << "...";
        for (int i = 0; i < params.noPatches; i++)
        {
            for (int j = 0; j < params.noTrees; j++)
            {
                Mat dummySize = RV_readCSVMat(forestDir + "patch_" + to_string(i + 1) + "_tree_" + to_string(j + 1) + "_size.csv", 1, 1);
                Mat dummyMat = RV_readCSVMat(forestDir + "patch_" + to_string(i + 1) + "_tree_" + to_string(j + 1) + ".csv", 4, (int)dummySize.at<double>(0, 0));
                allForests[i][j].cutVar.reserve(dummyMat.cols);
                allForests[i][j].cutValue.reserve(dummyMat.cols);
                allForests[i][j].rightChild.reserve(dummyMat.cols);
                allForests[i][j].leafVal.reserve(dummyMat.cols);
                dummyMat.row(0).copyTo(allForests[i][j].cutVar);
                dummyMat.row(1).copyTo(allForests[i][j].cutValue);
                dummyMat.row(2).copyTo(allForests[i][j].rightChild);
                dummyMat.row(3).copyTo(allForests[i][j].leafVal);
                //cout << "patch: " << i << " tree: " << j << endl;
            }
        }
        cout << "done!" << endl;
        return allForests;
    }

    vector<double> RV_computeHist(vector<double> vec, int noBins)
    {
        // supposedly vec has exactly noBins unique values
        const double eps = 1.0 / vec.size();
        vector<double> out(noBins);
        out.assign(noBins, 0);
        for (int i = 0; i < (int)vec.size(); i++)
        {
            out[(int)vec[i] - 1] += eps;
        }
        return out;
    }

    vector<double> RV_testForest(Mat localData, vector<randomTree> &localForest, paramList params, int numberOfClasses)
    {
        vector<double> votes(params.noTrees);
        votes.assign(params.noTrees, 0);
        for (int k = 0; k < params.noTrees; k++)
        {
            randomTree tree = localForest[k];
            int currNode = 0;
            while (tree.cutVar[currNode] > 0)
            {
                if (localData.at<double>(tree.cutVar[currNode] - 1) > tree.cutValue[currNode])
                {
                    currNode = tree.rightChild[currNode];
                }
                else
                {
                    currNode = tree.rightChild[currNode] - 1;
                }
            }
            votes[k] = tree.leafVal[currNode];
        }
        vector<double> probs = RV_computeHist(votes, numberOfClasses);
        return probs;
    }


    Rect RV_getBoundingBox(const Mat &im3D, paramList p) {

        Rect bbox;
        int min_x = im3D.cols;
        int min_y = im3D.rows;
        int max_x = 0;
        int max_y = 0;
        int p_width = p.patchSize;
        int p_height = p.patchSize;

        for (int y = 0; y < im3D.rows; y++)
        {
            const double *Mi = im3D.ptr<double>(y);
            for (int x = 0; x < im3D.cols; x++) {

                if (Mi[x] > 0) {

                    min_x = MIN(min_x, x);
                    min_y = MIN(min_y, y);
                    max_x = MAX(max_x, x);
                    max_y = MAX(max_y, y);
                }

            }
        }

        int new_w = max_x - min_x;
        int new_h = max_y - min_y;

        bbox.x = MIN(im3D.cols - 1, MAX(0 , min_x));
        bbox.y = MIN(im3D.rows - 1, MAX(0 , min_y));

        //int new_w = max_x - min_x + p_width;
        //int new_h = max_y - min_y + p_height;

        //bbox.x = MIN( im3D.cols-1, MAX( 0 , min_x - p_width/2 ) );
        //bbox.y = MIN( im3D.rows-1, MAX( 0 , min_y - p_height/2) );

        bbox.width  = MAX(0, MIN(new_w, im3D.cols - bbox.x));
        bbox.height = MAX(0, MIN(new_h, im3D.rows - bbox.y));

        return bbox;
    }

    double RV_computeNorm(vector<double> vec1, vector<double> vec2)
    {
        double result = 0;
        int dim = vec1.size();
        vector<double> diff(dim);
        double sumSq = 0;
        for (int i = 0; i < dim; i++)
        {
            diff[i] = vec1[i] - vec2[i];
            sumSq += pow(diff[i], 2);
        }
        result = sqrt(sumSq);
        return result;
    }

    double RV_computeMean(vector<double> vec)
    {
        double sum = 0;
        for (int k = 0; k < (int)vec.size(); k++)
        {
            sum += vec[k];
        }
        return sum / vec.size();
    }

    Mat meanShift(Mat dataPts, double bandWidth, int *maxClustPointer)
    {
        *maxClustPointer = -1;
        int biggestClusterSize = 0;
        int numDim = dataPts.cols;
        int numPts = dataPts.rows;
        int numClust = -1;
        double bandSq = bandWidth * bandWidth;
        std::vector<int> initPtInds(numPts);
        for (int k = 0; k < (int)initPtInds.size(); k++)
            initPtInds[k] = k;

        double stopThresh = 1e-3 * bandWidth;

        Mat clustCent(0, numDim, CV_64FC1);

        vector<bool> beenVisitedFlag(numPts);
        int numInitPts = numPts;
        //vector<int> clusterVotes(numPts);

        while (numInitPts > 0)
        {
            int tempInd = (int)std::ceil((numInitPts - 1 - 1e-6) * std::rand() / RAND_MAX);
            int stInd = initPtInds[tempInd];

            std::vector<double> myMean(numDim);
            for (int i = 0; i < numDim; i++)
            {
                myMean[i] = (double)dataPts.at<double>(stInd, i);
            }

            vector<int> thisClusterVotes(numPts);

            while (1)
            {
                vector<double> sqDistToAll(numPts);
                for (int i = 0; i < numPts; i++)
                {
                    double result = 0;
                    for (int j = 0; j < numDim; j++)
                    {
                        double diff = (double)dataPts.at<double>(i, j) - myMean[j];
                        result += pow(diff, 2);
                    }
                    sqDistToAll[i] = result;
                }
                vector<bool> inInds(numPts);
                for (int i = 0; i < numPts; i++)
                {
                    inInds[i] = sqDistToAll[i] < bandSq;
                    if (inInds[i] == true)
                    {
                        thisClusterVotes[i]++;
                    }
                }

                int countTrues = count_if(inInds.begin(), inInds.end(), [](bool b) {
                    return b == true;
                });
                vector<double> myOldMean = myMean;
                cv::Mat tempData(countTrues, numDim, CV_64FC1);
                int localIdx = 0;
                for (int i = 0; i < (int)inInds.size(); i++)
                {
                    if (inInds[i] == true)
                    {
                        for (int j = 0; j < numDim; j++)
                        {
                            tempData.at<double>(localIdx, j) = (double)dataPts.at<double>(i, j);
                        }
                        localIdx++;
                        beenVisitedFlag[i] = true;
                    }
                }
                Mat myMeanMat;
                reduce(tempData, myMeanMat, 0, CV_REDUCE_AVG);
                myMeanMat.copyTo(myMean);

                // compute the 2-norm of the difference-between-means vector
                double meanNorm = RV_computeNorm(myOldMean, myMean);

                if (meanNorm < stopThresh)
                {
                    int mergeWith = -1;
                    for (int cn = 0; cn <= numClust; cn++)
                    {
                        vector<double> localClustCent(numDim);
                        clustCent.row(cn).copyTo(localClustCent);
                        double distToOther = RV_computeNorm(myMean, localClustCent);

                        if (distToOther < bandWidth / 2)
                        {
                            mergeWith = cn;
                            break;
                        }
                    }

                    if (mergeWith >= 0)
                    {
                        Mat localMat = 0.5 * (myMeanMat + clustCent.row(mergeWith));
                        localMat.copyTo(clustCent.row(mergeWith));
                    }
                    else
                    {
                        numClust++;
                        clustCent.push_back(myMeanMat);
                        if (tempData.rows > biggestClusterSize)
                        {
                            biggestClusterSize = tempData.rows;
                            *maxClustPointer = *maxClustPointer + 1;
                        }
                        //myMeanMat.copyTo(clustCent.row(numClust));
                    }
                    break;
                }
            }

            initPtInds.clear();
            for (int i = 0; i < (int)beenVisitedFlag.size(); i++)
            {
                if (beenVisitedFlag[i] == false)
                {
                    initPtInds.push_back(i);
                }
            }
            numInitPts = initPtInds.size();
        }
        return clustCent;
    }

    Mat RV_preprocessDepthFrame(Mat frame)
    {
        Mat output;
        double minVal = 100;
        double maxVal = -100;
        Point minLoc, maxLoc;

        for (int i = 0; i < frame.rows; i++)
        {
            for (int j = 0; j < frame.cols; j++)
            {
                if ((frame.at<double>(i, j) < minVal) & (frame.at<double>(i, j) != -100))
                {
                    minVal = frame.at<double>(i, j);
                    minLoc.x = i;
                    minLoc.y = j;
                }

                if (frame.at<double>(i, j) > maxVal)
                {
                    maxVal = frame.at<double>(i, j);
                    maxLoc.x = i;
                    maxLoc.y = j;
                }
            }
        }

        for (int i = 0; i < frame.rows; i++)
        {
            for (int j = 0; j < frame.cols; j++)
            {
                if (frame.at<double>(i, j) != -100)
                {
                    frame.at<double>(i, j) = 255 - (frame.at<double>(i, j) - minVal) / (maxVal - minVal) * 254;
                }
                else
                {
                    frame.at<double>(i, j) = 0;
                }
            }
        }

        transpose(frame, output);
        return output;
    }

    void RV_featExtractionSingleFrame(Mat frame, paramList params, vector<double> *bgPerc, vector<Mat> &featData)
    {
        featData.clear();
        featData.resize((unsigned int)params.noPatches);
        for (int k = 0; k < params.noPatches; k++)
        {
            Mat dummyMat(1, (int)(params.d * params.noChannels), CV_64FC1);
            dummyMat.setTo(0);
            featData[k] = dummyMat;
        }

        int rows = frame.rows;
        int cols = frame.cols;

        vector<Mat> channels = RV_channelsExtractionSingleFrame(frame, params);
        vector<Mat> channelsInt(params.noChannels);
        vector<Mat> maskInt(params.noChannels);

        for (int i = 0; i < params.noChannels; i++)
        {
            Mat localChannel = channels[i];
            Mat localChannelInt(rows + 1, cols + 1, CV_64FC1);
            localChannelInt.setTo(0);
            integral(localChannel, localChannelInt);

            Mat localMask(rows, cols, CV_32FC1);
            localMask.setTo(0);
            localChannel.convertTo(localChannel, CV_32FC1); // for some (probably) stupid reason,
            // m***** f***** "threshold" function does not work with CV_64FC1...
            threshold(localChannel, localMask, 0.001, 1, THRESH_BINARY);

            Mat localMaskInt(rows + 1, cols + 1, CV_64FC1);
            localMaskInt.setTo(0);
            integral(localMask, localMaskInt);
            channelsInt[i] = localChannelInt;
            maskInt[i] = localMaskInt;
        }

        for (int k = 0; k < params.patchCoords.rows; k++)
        {
            Mat frameAux(frame, Rect((int)params.patchCoords.at<double>(k, 1),
                                     (int)params.patchCoords.at<double>(k, 0),
                                     (int)params.patchSize,
                                     (int)params.patchSize));
            double countBG = 0;
            for (int i = 1; i < frameAux.rows; i++) // first row and column are not covered by the rectangular features
                // so yes, index should start from 1
            {
                for (int j = 1; j < frameAux.cols; j++) // same here
                {
                    if (frameAux.at<double>(i, j) == 0)
                    {
                        countBG++;
                    }
                }
            }
            (*bgPerc)[k] = countBG / (params.patchSize - 1) / (params.patchSize - 1);

            vector<Mat> localImageInt(params.noChannels);
            vector<Mat> localMaskInt(params.noChannels);
            for (int i = 0; i < params.noChannels; i++)
            {
                Mat dummyMat1(channelsInt[i], Rect((int)params.patchCoords.at<double>(k, 1) + 1,
                                                   (int)params.patchCoords.at<double>(k, 0) + 1,
                                                   (int)params.patchSize,
                                                   (int)params.patchSize));
                localImageInt[i] = dummyMat1;
                Mat dummyMat2(maskInt[i], Rect((int)params.patchCoords.at<double>(k, 1) + 1,
                                               (int)params.patchCoords.at<double>(k, 0) + 1,
                                               (int)params.patchSize,
                                               (int)params.patchSize));
                localMaskInt[i] = dummyMat2;
            }

            Mat feats = RV_computeDiffFeats(localImageInt, localMaskInt, params.patchFeats[k]);
            featData[k] = feats;
        }
        // return featData;
    }

    Mat RV_computeDiffFeats(vector<Mat> imageInt, vector<Mat> maskInt, Mat localFeat)
    {
        Mat feats(1, localFeat.rows * imageInt.size(), CV_64FC1);
        feats.setTo(0);

        //int numRectangles = params.patchFeats[0].cols / 4;
        for (int i = 0; i < (int)imageInt.size(); i++)
        {
            Mat localImg = imageInt[i];
            Mat localMask = maskInt[i];
            for (int k = 0; k < localFeat.rows; k++)
            {
                //vector<int> v(localFeat.cols);
                //localFeat.row(k).copyTo(v);

                // keep in mind that the coordinates of the rectangles are obeying Matlab indexing, therefore adaptation is performed explicitly here

                double a1 = localImg.at<double>(localFeat.at<uchar>(k, 3) - 1, localFeat.at<uchar>(k, 2) - 1) -
                            localImg.at<double>(localFeat.at<uchar>(k, 3) - 1, localFeat.at<uchar>(k, 0) - 2) -
                            localImg.at<double>(localFeat.at<uchar>(k, 1) - 2, localFeat.at<uchar>(k, 2) - 1) +
                            localImg.at<double>(localFeat.at<uchar>(k, 1) - 2, localFeat.at<uchar>(k, 0) - 2);
                double a2 = localImg.at<double>(localFeat.at<uchar>(k, 7) - 1, localFeat.at<uchar>(k, 6) - 1) -
                            localImg.at<double>(localFeat.at<uchar>(k, 7) - 1, localFeat.at<uchar>(k, 4) - 2) -
                            localImg.at<double>(localFeat.at<uchar>(k, 5) - 2, localFeat.at<uchar>(k, 6) - 1) +
                            localImg.at<double>(localFeat.at<uchar>(k, 5) - 2, localFeat.at<uchar>(k, 4) - 2);
                /*double a3 = localImg.at<double>(localFeat.at<uchar>(k, 11) - 1, localFeat.at<uchar>(k, 10) - 1) -
                    localImg.at<double>(localFeat.at<uchar>(k, 11) - 1, localFeat.at<uchar>(k, 8) - 2) -
                    localImg.at<double>(localFeat.at<uchar>(k, 9) - 2, localFeat.at<uchar>(k, 10) - 1) +
                    localImg.at<double>(localFeat.at<uchar>(k, 9) - 2, localFeat.at<uchar>(k, 8) - 2);
                double a4 = localImg.at<double>(localFeat.at<uchar>(k, 15) - 1, localFeat.at<uchar>(k, 14) - 1) -
                    localImg.at<double>(localFeat.at<uchar>(k, 15) - 1, localFeat.at<uchar>(k, 12) - 2) -
                    localImg.at<double>(localFeat.at<uchar>(k, 13) - 2, localFeat.at<uchar>(k, 14) - 1) +
                    localImg.at<double>(localFeat.at<uchar>(k, 13) - 2, localFeat.at<uchar>(k, 12) - 2);*/

                double z1 = localMask.at<double>(localFeat.at<uchar>(k, 3) - 1, localFeat.at<uchar>(k, 2) - 1) -
                            localMask.at<double>(localFeat.at<uchar>(k, 3) - 1, localFeat.at<uchar>(k, 0) - 2) -
                            localMask.at<double>(localFeat.at<uchar>(k, 1) - 2, localFeat.at<uchar>(k, 2) - 1) +
                            localMask.at<double>(localFeat.at<uchar>(k, 1) - 2, localFeat.at<uchar>(k, 0) - 2);
                double z2 = localMask.at<double>(localFeat.at<uchar>(k, 7) - 1, localFeat.at<uchar>(k, 6) - 1) -
                            localMask.at<double>(localFeat.at<uchar>(k, 7) - 1, localFeat.at<uchar>(k, 4) - 2) -
                            localMask.at<double>(localFeat.at<uchar>(k, 5) - 2, localFeat.at<uchar>(k, 6) - 1) +
                            localMask.at<double>(localFeat.at<uchar>(k, 5) - 2, localFeat.at<uchar>(k, 4) - 2);
                /*double z3 = localMask.at<double>(localFeat.at<uchar>(k, 11) - 1, localFeat.at<uchar>(k, 10) - 1) -
                    localMask.at<double>(localFeat.at<uchar>(k, 11) - 1, localFeat.at<uchar>(k, 8) - 2) -
                    localMask.at<double>(localFeat.at<uchar>(k, 9) - 2, localFeat.at<uchar>(k, 10) - 1) +
                    localMask.at<double>(localFeat.at<uchar>(k, 9) - 2, localFeat.at<uchar>(k, 8) - 2);
                double z4 = localMask.at<double>(localFeat.at<uchar>(k, 15) - 1, localFeat.at<uchar>(k, 14) - 1) -
                    localMask.at<double>(localFeat.at<uchar>(k, 15) - 1, localFeat.at<uchar>(k, 12) - 2) -
                    localMask.at<double>(localFeat.at<uchar>(k, 13) - 2, localFeat.at<uchar>(k, 14) - 1) +
                    localMask.at<double>(localFeat.at<uchar>(k, 13) - 2, localFeat.at<uchar>(k, 12) - 2);*/

                double mz1 = (z1 > 1) ? z1 : 1;
                double mz2 = (z2 > 1) ? z2 : 1;
                /*double mz3 = (z3 > 1) ? z3 : 1;
                double mz4 = (z4 > 1) ? z4 : 1;*/

                //double featVal = a1 / mz1 + a3 / mz3 - a2 / mz2 - a4 / mz4;
                double featVal = a1 / mz1 - a2 / mz2;
                feats.at<double>(0, i * localFeat.rows + k) = featVal;
            }
        }

        return feats;
    }

    vector<Mat> RV_channelsExtractionSingleFrame(Mat frame, paramList params)
    {
        vector<Mat> output(params.noChannels);
        for (int i = 0; i < params.noChannels; i++)
        {
            Mat buff(frame.rows, frame.cols, CV_64FC1);
            buff.setTo(0);
            output[i] = buff;
        }

        output[0] = frame;
        Mat dx(frame.rows, frame.cols, CV_64FC1);
        Mat dy(frame.rows, frame.cols, CV_64FC1);

        Sobel(frame, dx, CV_64FC1, 0, 1);
        Sobel(frame, dy, CV_64FC1, 1, 0);

        Mat magnitudeAux(frame.rows, frame.cols, CV_64FC1);
        Mat orientation(frame.rows, frame.cols, CV_64FC1);

        for (int i = 0; i < frame.rows; i++)
        {
            for (int j = 0; j < frame.cols; j++)
            {
                magnitudeAux.at<double>(i, j) = sqrt(pow(dx.at<double>(i, j), 2) + pow(dy.at<double>(i, j), 2));
                orientation.at<double>(i, j) = atan2(dx.at<double>(i, j), dy.at<double>(i, j));
            }
        }

        Mat magnitude(frame.rows, frame.cols, CV_64FC1);
        log(magnitudeAux + 1.0, magnitude); // switch to log scale to attenuate differences...

        output[1] = magnitude;

        /*namedWindow("frame", CV_WINDOW_AUTOSIZE);
        int flag = RV_imshow("frame", frame);
        namedWindow("magnitude", CV_WINDOW_AUTOSIZE);
        flag = RV_imshow("magnitude", magnitude);
        namedWindow("orientation", CV_WINDOW_AUTOSIZE);
        flag = RV_imshow("orientation", orientation);*/

        //setMouseCallback("image2", onMouse, 0);

        // compute gradient histograms for each of the 6 discrete orientation intervals
        // if an orient falls inside a particular interval, we assign the pixel a value proportional
        // to the gradient magnitude weighted by a peaked Gaussian whose mean is the center of the
        // orientation interval and std = 1/(sqrt(2*pi))/5 (5 comes from the attempt of replicating Dollars toolbox)
        // of course, pdf(mu) should be 1, so we compensate the small std by dividing the pdf by 5

        // using Sobel gradient results in orients in the range (-pi;pi) therefore we split this interval in 6 complementary subintervals

        double sigma = 1 / sqrt(2 * M_PI) / 5;
        for (int k = 0; k < 6; k++)
        {
            double mu = -5 * M_PI / 6 + k * 2 * M_PI / 6;
            Mat localChannel(frame.rows, frame.cols, CV_64FC1);
            for (int i = 0; i < frame.rows; i++)
            {
                for (int j = 0; j < frame.cols; j++)
                {
                    double valuePdf = RV_gaussPdf(orientation.at<double>(i, j), mu, sigma) / 5;
                    localChannel.at<double>(i, j) = magnitude.at<double>(i, j) * valuePdf;
                }
            }
            output[k + 2] = localChannel;
        }

        // compute the LBP map of the original (grayscaled) depth image
        Mat lbpMap = RV_lbp(frame);
        Mat lbpMap64(lbpMap.rows, lbpMap.cols, CV_64FC1);
        lbpMap.convertTo(lbpMap64, CV_64FC1);

        for (int i = 1; i < frame.rows - 1; i++)
        {
            for (int j = 1; j < frame.cols - 1; j++)
            {
                output[8].at<double>(i, j) = lbpMap64.at<double>(i - 1, j - 1);
            }
        }
        return output;
    }

    double RV_gaussPdf(double x, double mu, double sigma)
    {
        /*
            x = double(int(x * 10)) / 10;
            static map<double, double> pdfMap;
            if (pdfMap.find(x) != pdfMap.end())
            {
                return pdfMap[x];
            }*/
        double aux = -pow(x - mu, 2) / (2 * pow(sigma, 2));
        double out = 1 / (sqrt(2 * M_PI) * sigma) * exp(aux);
        /*pdfMap[x] = out;*/
        return out;

    }

    int RV_imshow(string windowName, Mat img)
    {
        double minVal, maxVal;
        Mat draw(img.rows, img.cols, CV_8UC1);
        minMaxLoc(img, &minVal, &maxVal);
        img.convertTo(draw, CV_8UC1, 255.0 / (maxVal - minVal), -minVal * 255.0 / (maxVal - minVal));
        imshow(windowName, draw);
        return 1;
    }

    Mat RV_lbp(const Mat &src)
    {
        Mat dst;
        dst = Mat::zeros(src.rows - 2, src.cols - 2, CV_8UC1);
        for (int i = 1; i < src.rows - 1; i++) {
            for (int j = 1; j < src.cols - 1; j++) {
                uchar center = (uchar)src.at<double>(i, j);
                unsigned char code = 0;
                code |= ((uchar)src.at<double>(i - 1, j - 1) > center) << 7;
                code |= ((uchar)src.at<double>(i - 1, j) > center) << 6;
                code |= ((uchar)src.at<double>(i - 1, j + 1) > center) << 5;
                code |= ((uchar)src.at<double>(i, j + 1) > center) << 4;
                code |= ((uchar)src.at<double>(i + 1, j + 1) > center) << 3;
                code |= ((uchar)src.at<double>(i + 1, j) > center) << 2;
                code |= ((uchar)src.at<double>(i + 1, j - 1) > center) << 1;
                code |= ((uchar)src.at<double>(i, j - 1) > center) << 0;
                dst.at<uchar>(i - 1, j - 1) = code;
            }
        }
        return 255 - dst;
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/FacialExpressions/ferLocalFunctions.h
================================================
#ifndef FERLOCALFUNCTIONS_H
#define FERLOCALFUNCTIONS_H

#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stdint.h>
#include "opencv2/core/core.hpp"

namespace fer
{

# define M_PI           3.14159265358979323846  /* pi */

    using namespace std;
    using namespace cv;

    struct paramList
    {
        int d;
        int patchSize;
        int stride;
        int featSize;
        int noPatches;
        int noChannels;
        int noTrees;
        Mat patchCoords;
        vector<Mat> patchFeats;
    };

    struct randomTree
    {
        vector<double> cutVar, cutValue, rightChild, leafVal;
    };

    struct headPoseInfo
    {
        double x, y, yaw, tilt;
    };

    vector<string> get_all_files_names_within_folder(string folder);

    Mat RV_readCSVMat(string csvFrameName, int lin, int col);
    void RV_readParamList(const string foldername, paramList *p);
    vector<vector<randomTree>> RV_readAllForests(string forestDir, paramList params);
    vector<double> RV_computeHist(vector<double> vec, int noBins);

    vector<double> RV_testForest(Mat localData, vector<randomTree> &localForest, paramList params, int numberOfClasses);

    Rect RV_getBoundingBox(const Mat &im3D, paramList p);
    double RV_computeNorm(vector<double> vec1, vector<double> vec2);
    double RV_computeMean(vector<double> vec);
    Mat RV_preprocessDepthFrame(Mat frameIn);
    void RV_featExtractionSingleFrame(Mat frame, paramList params, vector<double> *bgPerc, vector<Mat> &result);
    vector<Mat> RV_channelsExtractionSingleFrame(Mat frame, paramList params);
    Mat RV_computeDiffFeats(vector<Mat> imageInt, vector<Mat> maskInt, Mat localFeat);

    double RV_gaussPdf(double x, double mu, double sigma);
    int RV_imshow(string windowName, Mat img);

    Mat RV_lbp(const Mat &src);

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/CylinderOptimizedFeatureCalculator.cpp
================================================
//#include "CylinderOptimizedFeatureCalculator.h"

namespace hpe
{

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/CylinderOptimizedFeatureCalculator.h
================================================
#pragma once

#ifndef CYLINDEROPTIMIZEDFEATURECALCULATOR_H
#define CYLINDEROPTIMIZEDFEATURECALCULATOR_H

#include <Features/Calculator/FeatureCalculatorBase.h>

#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/pcl_visualizer.h>

#include <boost/math/special_functions/fpclassify.hpp>

#include <UI/ShowCloud.h>

namespace hpe
{
    enum FeatureType { Depth, RGB };

    template <class PointType, class NormalType>
    class CylinderOptimizedFeatureCalculator : public FeatureCalculatorBase <PointType, NormalType>
    {
        public:
            typedef PointType TPoint;
            typedef NormalType TNormal;
            typedef std::shared_ptr<IPatchSampler<PointType>> Sampler;
            typedef pcl::PointCloud<PointType> Cloud;
            typedef pcl::PointCloud<NormalType> NormalCloud;
            typedef pcl::search::KdTree<PointType> Search;

            CylinderOptimizedFeatureCalculator(Sampler sampler, FeatureType featureType)
                : FeatureCalculatorBase<PointType, NormalType>(sampler), m_visualize(false), m_featureType(featureType)
            {
            }

            ~CylinderOptimizedFeatureCalculator(void)
            {
            }

            void SetFeatureSize(cv::Size size)
            {
                m_featureSize = size;
            }

            cv::Mat GetFeatures(typename Cloud::Ptr &cloud)
            {
                m_result = CreateResult();
                m_featureNumber = 0;
                this->Calculate(cloud);
                return m_result;
            }

        protected:
            void PreCompute() {}

            cv::Mat CreateResult()
            {
                if (m_featureType == FeatureType::Depth)
                {
                    return cv::Mat::ones(1, m_featureSize.width * m_featureSize.height, CV_32FC1) * -100;
                }
                else if (m_featureType == FeatureType::RGB)
                {
                    return cv::Mat::zeros(1, m_featureSize.width * m_featureSize.height, CV_8UC3);
                }
            }

            void PreCompute(typename Cloud::Ptr cloud, pcl::ModelCoefficients &coefficients)
            {
                m_columns.clear();
                m_rows.clear();

                m_referencePoint.x = coefficients.values[0];
                m_referencePoint.y = coefficients.values[1];
                m_referencePoint.z = coefficients.values[2];

                m_phiRange.first = coefficients.values[3];
                m_phiRange.second = coefficients.values[4];
                m_phiSteps = (int)coefficients.values[5];

                m_yRange.first = coefficients.values[6];
                m_yRange.second = coefficients.values[7];
                m_ySteps = (int)coefficients.values[8];

                //std::vector<std::vector<int>> indices;
                m_columns.resize(m_phiSteps);
                m_rows.resize(m_ySteps);

                for (int i = 0; i < cloud->points.size(); i += 1)
                {
                    PointType pt = cloud->points[i];
                    if (boost::math::isnan(pt.x) || boost::math::isnan(pt.y) || boost::math::isnan(pt.z))
                    {
                        continue;
                    }
                    int column = GetPointColumn(pt);
                    if (column != -1)
                    {
                        if (column > 0) m_columns[column - 1].push_back(i);
                        m_columns[column].push_back(i);
                        if (column < m_phiSteps - 1) m_columns[column + 1].push_back(i);
                    }
                    int row = GetPointRow(pt);
                    if (row != -1)
                    {
                        if (row > 0) m_rows[row - 1].push_back(i);
                        m_rows[row].push_back(i);
                        if (row < m_ySteps - 1) m_rows[row + 1].push_back(i);
                    }
                }

                for (int i = 0; i < m_phiSteps; i += 1)
                {
                    std::sort(m_columns[i].begin(), m_columns[i].end());
                }
                for (int i = 0; i < m_ySteps; i += 1)
                {
                    std::sort(m_rows[i].begin(), m_rows[i].end());
                }

                if (m_visualize)
                {
                    pcl::visualization::PCLVisualizer v("Segments");
                    v.addPointCloud<PointType>(cloud);
                    v.addPointCloud<PointType>(cloud, "pts");
                    v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1, 0, 0, "pts");
                    for (int i = 0; i < m_phiSteps; i += 1)
                    {
                        typename Cloud::Ptr subcloud(new Cloud);
                        pcl::copyPointCloud(*cloud, m_columns[i], *subcloud);
                        v.updatePointCloud<PointType>(subcloud, "pts");
                        v.spinOnce(100);
                    }
                    v.removeAllPointClouds();
                }

                /*m_trees.clear();
                m_trees.resize(m_phiSteps);
                for (int i = 0; i < m_phiSteps; i += 1)
                {
                    Cloud::Ptr subcloud(new Cloud);
                    pcl::copyPointCloud(*cloud, indices[i], *subcloud);
                    m_trees[i].setInputCloud(subcloud);
                }*/

            }
            void ComputeFeature(typename Cloud::Ptr cloud, PointType &point, NormalType &normal)
            {
                int column = GetPointColumn(point);
                if (column == -1)
                {
                    throw HPEException("CylinderOptimizedFeatureCalculator::ComputeFeature - internal structures corrupted");
                }
                int row = GetPointRow(point);
                if (column == -1)
                {
                    throw HPEException("CylinderOptimizedFeatureCalculator::ComputeFeature - internal structures corrupted");
                }

                std::vector<int> indices = GetIntersection(column, row);

                if (m_visualize)
                {
                    /*Cloud::Ptr subcloud(new Cloud);
                    pcl::copyPointCloud(*treeCloud, indices, *subcloud);
                    subcloud->push_back(point);
                    pcl::visualization::PCLVisualizer v("sub");
                    v.addPointCloud<PointType>(cloud);
                    v.addPointCloud<PointType>(subcloud, "1");
                    v.addPointCloud<PointType>(treeCloud, "2");
                    v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1, 0, 0, "1");
                    v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "1");
                    v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 0, 1, "2");
                    v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "2");
                    v.spin();*/
                }

                if (indices.size() > 0)
                {
                    std::vector<float> distances;
                    for (int i = 0; i < indices.size(); i += 1)
                    {
                        distances.push_back((point.getVector3fMap() - cloud->points[indices[i]].getVector3fMap()).norm());
                    }

                    PointType interpolated;
                    if (indices.size() == 1)
                    {
                        interpolated = cloud->points[indices[0]];
                    }
                    else
                    {
                        interpolated = Interpolate(cloud, indices, distances);
                    }

                    if (m_featureType == FeatureType::Depth)
                    {
                        float depth = (interpolated.getVector3fMap() - point.getVector3fMap()).norm();

                        float pointProjectionRadius = (std::pow(m_referencePoint.x - point.x, 2) + std::pow(m_referencePoint.z - point.z, 2));
                        float interpolatedProjectionRadius = (std::pow(m_referencePoint.x - interpolated.x, 2) + std::pow(m_referencePoint.z - interpolated.z, 2));

                        if (pointProjectionRadius < interpolatedProjectionRadius)
                        {
                            depth = -depth;
                        }

                        m_result.at<float>(m_featureNumber) = depth;
                    }
                    else if (m_featureType == FeatureType::RGB)
                    {
                        cv::Vec3b color = cv::Vec3b(interpolated.b, interpolated.g, interpolated.r);
                        m_result.at<cv::Vec3b>(m_featureNumber) = color;
                    }
                }

                m_featureNumber += 1;
            }
        private:

            int GetPointColumn(PointType pt)
            {
                float phiStep = (m_phiRange.second - m_phiRange.first) / m_phiSteps;
                float angle = std::atan2(pt.z - m_referencePoint.z, pt.x - m_referencePoint.x);
                int segment = (angle - m_phiRange.first - phiStep / 2) / phiStep;
                if (segment > m_phiSteps - 1 || segment < 0)
                {
                    return -1;
                }
                return segment;
            }

            int GetPointRow(PointType pt)
            {
                float yStep = (m_yRange.second - m_yRange.first) / m_ySteps;
                int row = (pt.y - m_yRange.first - yStep / 2) / yStep;
                if (row > m_ySteps - 1 || row < 0)
                {
                    return -1;
                }
                return row;
            }

            std::vector<int> GetIntersection(int column, int row)
            {
                std::vector<int> result;

                std::set_intersection(m_columns[column].begin(), m_columns[column].end(), m_rows[row].begin(), m_rows[row].end(), std::back_inserter(result));

                return result;
            }

            PointType Interpolate(typename Cloud::Ptr &cloud, std::vector<int> &indices, std::vector<float> &distances)
            {
                float totalDistance = 0;
                for (int i = 0; i < distances.size(); i += 1)
                {
                    totalDistance += distances[i];
                }

                PointType result;
                int n = indices.size();

                for (int i = 0; i < n; i++)
                {
                    PointType p = cloud->at(indices[i]);
                    float currentDistance = distances[i];
                    float c = (totalDistance - currentDistance) / ((n - 1) * totalDistance);
                    result.x += c * p.x;
                    result.y += c * p.y;
                    result.z += c * p.z;
                    result.r += c * (float)p.r;
                    result.g += c * (float)p.g;
                    result.b += c * (float)p.b;
                }
                return result;
            }

            std::vector<std::vector<int>> m_columns;
            std::vector<std::vector<int>> m_rows;

            std::vector<pcl::search::KdTree<PointType>> m_trees;

            pcl::PointXYZ m_referencePoint;

            std::pair<float, float> m_phiRange;
            int m_phiSteps;

            std::pair<float, float> m_yRange;
            int m_ySteps;

            bool m_visualize;
            cv::Mat m_result;
            cv::Size m_featureSize;
            int m_featureNumber;

            FeatureType m_featureType;
    };

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/FeatureCalculatorBase.h
================================================
#pragma once

#ifndef FEATURE_CALCULATOR_BASE_H
#define FEATURE_CALCULATOR_BASE_H

#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/search/kdtree.h>
#ifndef EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
#endif
#include <pcl/features/principal_curvatures.h>
#include <pcl/features/normal_3d.h>

#include <Features/Sampler/IPatchSampler.h>
#include <Features/IFeature.h>
#include <Filter/Filters.h>
#include <Landmarks.h>

namespace hpe
{
    template<typename PointType, typename NormalType>
    class FeatureCalculatorBase
    {
        public:
            void SetLandmarks(const typename Common<PointType>::Landmarks &landmarks)
            {
                m_landmarks = landmarks;
            }
        protected:
            typedef PointType TPoint;
            typedef NormalType TNormal;
            typedef std::shared_ptr<IPatchSampler<PointType>> Sampler;
            typedef pcl::PointCloud<PointType> Cloud;
            typedef pcl::PointCloud<NormalType> NormalCloud;
            typedef pcl::search::KdTree<PointType> Search;

            FeatureCalculatorBase(Sampler sampler)
                : m_sampler(sampler)
            {

            }

            void Calculate(typename Cloud::Ptr &cloud)
            {
                pcl::ModelCoefficients coefficients;
                if (m_landmarks.size() != 0)
                {
                    m_featurePoints = m_sampler->SampleCloud(cloud, m_landmarks, coefficients);
                    m_landmarks.clear();
                }
                else
                {
                    m_featurePoints = m_sampler->SampleCloud(cloud, coefficients);
                }

                auto normalCloud = m_featurePoints;

                int numberOfSamples = m_featurePoints->size();
                m_featureNumber = 0;

                if (coefficients.values.size() == 0)
                {
                    PreCompute();
                }
                else
                {
                    PreCompute(cloud, coefficients);
                }

                for (int i = 0; i < numberOfSamples; i++)
                {
                    auto gridPoint = m_featurePoints->at(i);
                    PointType point;
                    NormalType normal;

                    if ((boost::math::isnan(gridPoint.x) || boost::math::isnan(gridPoint.y) || boost::math::isnan(gridPoint.z)) == false)
                    {
                        // TODO make both usages:
                        int samplePointIndex = i; //GetReferencePoint(gridPoint);
                        point = m_featurePoints->at(samplePointIndex);
                        normal = normalCloud->at(samplePointIndex);
                    }

                    ComputeFeature(cloud, point, normal);

                    m_featureNumber++;
                }

                m_featureNumber = 0;
            }

            int GetReferencePoint(PointType &point)
            {
                std::vector<int> indices;
                std::vector<float> distances;

                m_search->nearestKSearch(point, 1, indices, distances);

                return indices[0];
            }

            int GetFeatureNumber()
            {
                return m_featureNumber;
            }

            int GetFeatureCount()
            {
                return m_featurePoints->size();
            }

            virtual void ComputeFeature(typename Cloud::Ptr cloud, PointType &point, NormalType &normal) = 0;
            virtual void PreCompute() = 0;
            virtual void PreCompute(typename Cloud::Ptr cloud, pcl::ModelCoefficients &coefficients) {}

            typename Search::Ptr m_search;
            Sampler m_sampler;

        private:
            int m_featureNumber;
            typename Common<PointType>::Landmarks m_landmarks;
            typename Cloud::Ptr m_featurePoints;
    };

}

#endif //FEATURE_CALCULATOR_BASE_H



================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/IFeatureCalculator.h
================================================
#pragma once

#ifndef I_FEATURE_CALCULATOR_H
#define I_FEATURE_CALCULATOR_H

#include "Interface/IInterface.h"

namespace hpe
{
    template <typename PointType>
    class IFeatureCalculator : public IInterface
    {
        public:
            virtual cv::Mat GetFeatures(typename pcl::PointCloud<PointType>::Ptr &cloud) = 0;
    };
}


#endif //I_FEATURE_CALCULATOR_H

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Features/IFeature.h
================================================
#pragma once

#ifndef I_FEATURE_H
#define I_FEATURE_H

#include <pcl/point_cloud.h>
#include <opencv2/opencv.hpp>

#include "Interface/IInterface.h"


namespace hpe
{
    template <typename PointType, typename NormalType>
    class IFeature : public IInterface
    {
        public:
            virtual cv::Mat Compute(typename pcl::PointCloud<PointType>::Ptr &cloud,
                                    PointType &point, NormalType &normal) = 0;

            virtual cv::Mat EmptyFeature() = 0;
    };
}

#endif //I_FEATURE_H

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Sampler/CylinderSampler.cpp
================================================
#define _CRT_SECURE_NO_WARNINGS

#include <opencv2\opencv.hpp>

#include "CylinderSampler.h"

#include <Exception/HPEException.h>
#include <pcl/common/common.h>

#include <boost/assign/std/vector.hpp>

#include <UI/ShowCloud.h>

#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d.h>
#include <pcl/io/ply_io.h>
#include <pcl/io/vtk_io.h>

using namespace boost::assign;

namespace hpe
{
    CylinderSampler::CylinderSampler(Range phiRange, Range zRange, int topRows, int bottomRows, int sampleColumns)
        : m_phiRange(phiRange), m_zRange(zRange), m_topRows(topRows),
          m_bottomRows(bottomRows), m_visualize(false), m_sampleColumns(sampleColumns),
          m_supportOptimizedSampling(false)
    {
        //m_rightEyeIndices += 0, 4;
        //m_leftEyeIndices += 8, 12;
        //m_rightEyeIndices += 0;
        //m_rightEyeIndices += 0, 1, 2, 3, 4, 5, 6, 7;
        //m_leftEyeIndices += 1;
        //m_leftEyeIndices += 8, 9, 10, 11, 12, 13, 14, 15;
        m_leftEyeIndices += 0;
        m_rightEyeIndices += 1;
    }

    CylinderSampler::~CylinderSampler(void)
    {
    }

    pcl::PointCloud<CylinderSampler::PointType>::Ptr CylinderSampler::SampleCloud(pcl::PointCloud<PointType>::Ptr &cloud)
    {
        CloudType::Ptr res(new CloudType);
        return res;
    }

    pcl::PointCloud<CylinderSampler::PointType>::Ptr CylinderSampler::SampleCloud(pcl::PointCloud<PointType>::Ptr &cloud, const Common<PointType>::Landmarks &landmarks, pcl::ModelCoefficients &coefficients)
    {
        CloudType::Ptr res(new CloudType);

        PointType leftEye = MeanPoint(landmarks, m_leftEyeIndices);
        PointType rightEye = MeanPoint(landmarks, m_rightEyeIndices);

        Eigen::Vector3f betweenEyeVector = leftEye.getArray3fMap() - rightEye.getArray3fMap();
        float eyeDistance = betweenEyeVector.norm();

        pcl::ModelCoefficients cylinder = ComputeCylinder(rightEye, leftEye);

        Eigen::Vector3f direction;
        direction << 0, 0, 1; // Works only when the cloud is oriented along OZ
        Range phiRange(CV_PI * m_phiRange.first, CV_PI * m_phiRange.second);

        float eyeY = cylinder.values[1];

        float maxY = eyeY + m_zRange.second * eyeDistance;
        float minY = eyeY - m_zRange.first * eyeDistance;

        int totalRows = m_bottomRows + m_topRows;
        float stepSize = (maxY - minY) / totalRows;

        std::vector<float> samplingYs;
        float samplingYStart = eyeY + (m_topRows - 1) * stepSize;
        for (int i = 0; i < totalRows; i++)
        {
            samplingYs.push_back(samplingYStart);
            samplingYStart -= stepSize;
        }

        CloudType::Ptr samplingCylinderTop = GenerateSamplingCloud(cylinder, direction, phiRange, m_sampleColumns, samplingYs);

        coefficients.values.clear();

        if (m_supportOptimizedSampling)
        {
            coefficients.values.push_back(cylinder.values[0]);
            coefficients.values.push_back(cylinder.values[1]);
            coefficients.values.push_back(cylinder.values[2]);

            coefficients.values.push_back(phiRange.first);
            coefficients.values.push_back(phiRange.second);
            coefficients.values.push_back(m_sampleColumns);

            coefficients.values.push_back(eyeY + (m_topRows - 1) * stepSize);
            coefficients.values.push_back(eyeY - m_bottomRows * stepSize);
            coefficients.values.push_back(totalRows);
        }

        if (m_visualize)
        {
            std::cout << samplingCylinderTop->size() << std::endl;

            pcl::PointCloud<pcl::PointXYZRGBA>::Ptr rgbCloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
            pcl::copyPointCloud(*cloud, *rgbCloud);

            CloudType::Ptr eyes(new CloudType);
            eyes->push_back(leftEye);
            eyes->push_back(rightEye);

            std::vector<float> eyeYs;
            eyeYs.push_back(eyeY);
            auto eyeLine = GenerateSamplingCloud(cylinder, direction, phiRange, m_sampleColumns, eyeYs);

            std::vector<pcl::visualization::Camera> cameras;

            pcl::visualization::PCLVisualizer vEyes("Eyes");
            vEyes.addPointCloud(rgbCloud, "c");
            vEyes.addPointCloud<PointType>(eyes, "e");
            vEyes.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1, 0, 0, "e");
            vEyes.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "e");
            vEyes.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "c");
            vEyes.setBackgroundColor(1, 1, 1);

            vEyes.spin();

            vEyes.getCameras(cameras);

            pcl::visualization::PCLVisualizer v("");
            v.addPointCloud(rgbCloud, "c");
            v.addPointCloud<PointType>(samplingCylinderTop, "cyl");
            v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 0, 1, "cyl");
            v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 1, 1, "cyl2");

            v.addCoordinateSystem();
            v.addPointCloud<PointType>(eyeLine, "EyeLine");
            v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1, 0, 0, "EyeLine");
            v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "EyeLine");
            v.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "c");
            v.setBackgroundColor(1, 1, 1);

            v.setCameraParameters(cameras[0]);
            v.spin();

        }

        return samplingCylinderTop;
    }

    pcl::ModelCoefficients CylinderSampler::ComputeCylinder(PointType p1, PointType p2)
    {
        pcl::ModelCoefficients result;

        Eigen::Vector3f distanceVector = p1.getArray3fMap() - p2.getArray3fMap();
        float distance = distanceVector.norm();

        PointType middlePoint;
        middlePoint.getArray3fMap() = p1.getVector3fMap() - distanceVector / 2;

        float r = distance * 1.2;
        float rsq = r * r;
        float offset = std::sqrt(distance * distance - (distance / 2) * (distance / 2));

        float a = distance / 2;
        float hsq = rsq - a * a;

        Eigen::Vector3f P2 = p1.getArray3fMap() + a * (distance / 2);

        float x = P2[0] + sqrt(hsq) * (p2.y - p1.y) / distance;
        float y = P2[1] - sqrt(hsq) * (p2.x - p1.x) / distance;

        middlePoint.z -= offset;

        result.values.resize(7);
        result.values[0] = middlePoint.x;
        result.values[1] = middlePoint.y;
        result.values[2] = middlePoint.z;

        result.values[3] = 0;
        result.values[4] = 1;
        result.values[5] = 0;

        result.values[6] = r;

        return result;
    }

    CylinderSampler::PointType CylinderSampler::MeanPoint(const Common<PointType>::Landmarks &landmarks, const std::vector<int> &indices)
    {
        PointType res;
        Eigen::Vector3f result;
        result << 0, 0, 0;
        for (int i = 0; i < indices.size(); i++)
        {
            Eigen::Vector3f p = landmarks[indices[i]].point.getArray3fMap();
            result += p;
        }
        result /= indices.size();
        res.getArray3fMap() = result;
        return res;
    }

    CylinderSampler::CloudType::Ptr CylinderSampler::GenerateSamplingCloud(pcl::ModelCoefficients cylinder, Eigen::Vector3f direction, Range phiRange, int phiSteps, std::vector<float> samplingYs)
    {
        float radius = cylinder.values[6];
        float phi = phiRange.first;
        float phiStep = (phiRange.second - phiRange.first) / phiSteps;
        CloudType::Ptr result(new CloudType);
        for (int currentPhi = 0; currentPhi < phiSteps; ++currentPhi)
        {
            PointType p;
            p.x = radius * std::cos(phi);
            p.z = radius * std::sin(phi);

            Eigen::Vector3f normalVector;
            normalVector << p.x, p.y, p.z;
            normalVector /= normalVector.norm();

            p.normal_x = -normalVector[0];
            p.normal_y = -normalVector[1];
            p.normal_z = -normalVector[2];

            for (int currentY = 0; currentY < samplingYs.size(); ++currentY)
            {
                PointType p2 = p;
                p2.y = samplingYs[currentY];
                result->push_back(p2);
            }

            phi += phiStep;
        }

        Eigen::Quaternionf rotation;
        Eigen::Vector3f sourceVector;
        sourceVector << 0, 0, 1;
        rotation.setFromTwoVectors(sourceVector, direction);


        Eigen::Matrix4f transofm = Eigen::Matrix4f::Identity();
        Eigen::Vector3f shift;
        shift << cylinder.values[0], 0, cylinder.values[2];
        transofm.block<3, 1>(0, 3) = shift;
        transofm.block<3, 3>(0, 0) = rotation.toRotationMatrix();

        pcl::transformPointCloud(*result, *result, transofm);

        PointType p13;
        p13.getArray3fMap() << cylinder.values[0], 0, cylinder.values[2];

        return result;
    }

    Eigen::Vector3f CylinderSampler::GetDirection(pcl::PointCloud<PointType>::Ptr &cloud, const Common<PointType>::Landmarks &landmarks)
    {
        pcl::NormalEstimation<PointType, pcl::Normal> ne;
        ne.setInputCloud(cloud);

        pcl::search::KdTree<PointType>::Ptr tree(new pcl::search::KdTree<PointType> ());
        ne.setSearchMethod(tree);

        pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>);

        ne.setRadiusSearch(0.3);

        ne.compute(*cloud_normals);

        pcl::Normal normal = cloud_normals->points[landmarks[m_noseTipIndex].index];

        Eigen::Vector3f direction;
        direction << normal.normal_x, normal.normal_y, normal.normal_z;
        return direction;
    }

    void CylinderSampler::SetVisualize(bool visualizeSampler)
    {
        m_visualize = visualizeSampler;
    }

    void CylinderSampler::SetEyeIndices(std::vector<int> &leftEyeIndices, std::vector<int> &rightEyeIndices)
    {
        m_leftEyeIndices = leftEyeIndices;
        m_rightEyeIndices = rightEyeIndices;
    }

    void CylinderSampler::SetSupportOptimizedSampling(bool support)
    {
        m_supportOptimizedSampling = support;
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Sampler/CylinderSampler.h
================================================
#pragma once

#include <Features/Sampler/IPatchSampler.h>

#include <pcl/ModelCoefficients.h>

#ifndef CYLINDERSAMPLER_H
#define CYLINDERSAMPLER_H

namespace hpe
{
    class CylinderSampler : public IPatchSampler<pcl::PointXYZRGBNormal>
    {
        public:
            typedef std::pair<float, float> Range;
            typedef pcl::PointXYZRGBNormal PointType;
            typedef pcl::PointCloud<PointType> CloudType;

            CylinderSampler(Range phiRange, Range zRange, int topRows, int bottomRows, int sampleColumns);
            ~CylinderSampler(void);

            pcl::PointCloud<PointType>::Ptr SampleCloud(pcl::PointCloud<PointType>::Ptr &cloud);
            pcl::PointCloud<PointType>::Ptr SampleCloud(pcl::PointCloud<PointType>::Ptr &cloud, const Common<PointType>::Landmarks &landmarks, pcl::ModelCoefficients &coefficients);

            void SetVisualize(bool visualizeSampler);
            void SetEyeIndices(std::vector<int> &leftEyeIndices, std::vector<int> &rightEyeIndices);
            void SetSupportOptimizedSampling(bool support);


        private:
            pcl::ModelCoefficients ComputeCylinder(PointType p1, PointType p2);
            PointType MeanPoint(const Common<PointType>::Landmarks &landmarks, const std::vector<int> &indices);
            CloudType::Ptr GenerateSamplingCloud(pcl::ModelCoefficients cylinder, Eigen::Vector3f direction, Range phiRange, int phiSteps, std::vector<float> samplingYs);
            Eigen::Vector3f GetDirection(pcl::PointCloud<PointType>::Ptr &cloud, const Common<PointType>::Landmarks &landmarks);
            std::vector<int> m_leftEyeIndices;
            std::vector<int> m_rightEyeIndices;
            int m_noseTipIndex;

            bool m_visualize;
            bool m_supportOptimizedSampling;

            Range m_phiRange;
            Range m_zRange;
            int m_topRows;
            int m_bottomRows;
            int m_sampleColumns;
    };
}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Sampler/IPatchSampler.h
================================================
#pragma once
#pragma once

#ifndef I_PATCH_SAMPLER
#define I_PATCH_SAMPLER

#include <pcl/point_cloud.h>
#include <pcl/ModelCoefficients.h>
#include <Interface/IInterface.h>
#include <Landmarks.h>

namespace hpe
{
    template <typename PointType>
    class IPatchSampler : public IInterface
    {
        public:
            virtual typename pcl::PointCloud<PointType>::Ptr SampleCloud(typename pcl::PointCloud<PointType>::Ptr &cloud) = 0;
            virtual typename pcl::PointCloud<PointType>::Ptr SampleCloud(typename pcl::PointCloud<PointType>::Ptr &cloud, const typename Common<PointType>::Landmarks &landmarks)
            {
                return SampleCloud(cloud);
            }
            virtual typename pcl::PointCloud<PointType>::Ptr SampleCloud(typename pcl::PointCloud<PointType>::Ptr &cloud, pcl::ModelCoefficients &coefficients)
            {
                coefficients.values.clear();
                return SampleCloud(cloud);
            }
            virtual typename pcl::PointCloud<PointType>::Ptr SampleCloud(typename pcl::PointCloud<PointType>::Ptr &cloud, const typename Common<PointType>::Landmarks &landmarks, pcl::ModelCoefficients &coefficients)
            {
                return SampleCloud(cloud, coefficients);
            }
    };
}

#endif //I_PATCH_SAMPLER

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/BoxFilter.h
================================================
#ifndef BOXFILTER_H
#define BOXFILTER_H

#include "Filter/ICloudFilter.h"
#include "Filter/Filters.h"

namespace hpe
{
    /**
     \class	BoxFilter
    
     \brief	A filter that cuts a box inside a point cloud.
    
     \author	Sergey
     \date	8/11/2015
    
     \tparam	PointType	Point type of the cloud.
     */

    template<typename PointType>
    class BoxFilter : public ICloudFilter<PointType>
    {
        public:
            typedef std::shared_ptr<BoxFilter> Ptr;

            //TODO consider using pcl::BoxClipper3D here (maybe)
            BoxFilter(float xFrom, float xTo, float yFrom, float yTo, float zFrom, float zTo)
                : m_xFrom(xFrom), m_xTo(xTo), m_yFrom(yFrom), m_yTo(yTo), m_zFrom(zFrom), m_zTo(zTo)
            {
            }

            typename pcl::PointCloud<PointType>::Ptr Filter(typename pcl::PointCloud<PointType>::Ptr &cloud)
            {
                auto x = std::minmax(m_xFrom, m_xTo);
                auto c1 = PassThrough<PointType>(cloud, x.first, x.second, "x");

                auto y = std::minmax(m_yFrom, m_yTo);
                auto c2 = PassThrough<PointType>(c1, y.first, y.second, "y");

                auto z = std::minmax(m_zFrom, m_zTo);
                auto c3 = PassThrough<PointType>(c2, z.first, z.second, "z");

                return c3;
            }

        private:
            float m_xFrom;
            float m_xTo;

            float m_yFrom;
            float m_yTo;

            float m_zFrom;
            float m_zTo;
    };
}

#endif // BOXFILTER_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/CenteredBoxFilter.h
================================================
#ifndef CENTEREDBOXFILTER_H
#define CENTEREDBOXFILTER_H

#include "Filter/ICenterCloudFilter.h"
#include "Filter/Filters.h"

#include <pcl/point_cloud.h>

namespace hpe
{
    template <typename PointT>
    class CenteredBoxFilter : public ICenterCloudFilter<PointT>
    {
        public:
            typedef pcl::PointCloud<PointT> Cloud;

            CenteredBoxFilter(float sizeX, float sizeY, float sizeZ)
                : m_sizeX(sizeX / 2), m_sizeY(sizeY / 2), m_sizeZ(sizeZ / 2)
            {

            }

            typename Cloud::Ptr Filter(typename Cloud::Ptr &cloud, float x, float y, float z)
            {
                float xFrom = x - m_sizeX;
                float xTo = x + m_sizeX;
                auto result = PassThrough<PointT>(cloud, xFrom, xTo, "x", cloud->isOrganized());

                float yFrom = y - m_sizeY;
                float yTo = y + m_sizeY;
                result = PassThrough<PointT>(result, yFrom, yTo, "y", cloud->isOrganized());

                float zFrom = z - m_sizeZ;
                float zTo = z + m_sizeZ;
                result = PassThrough<PointT>(result, zFrom, zTo, "z", cloud->isOrganized());

                return result;
            }


        private:
            float m_sizeX;
            float m_sizeY;
            float m_sizeZ;
    };
}

#endif // CENTEREDBOXFILTER_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/FilteringQueue.h
================================================
#pragma once

#ifndef FILTERINGQUEUE_H
#define FILTERINGQUEUE_H

#include <pcl/point_cloud.h>
#include <pcl/common/common.h>
#include <pcl/point_types.h>
#include <pcl/io/io.h>

#include "Filter/ICloudFilter.h"
#include "Filter/FunctorFilter.h"
#include <vector>


namespace hpe
{
	/**
	 \class	FilteringQueue
	
	 \brief	A queue of ICloudFilter objects that has ICloudFilter interface.
	
	 \author	Sergey
	 \date	8/11/2015
	
	 \tparam	PointType	Type of the point type.
	 */

	template<typename PointType>
    class FilteringQueue : public ICloudFilter<PointType>
    {
        public:
            typedef std::shared_ptr<FilteringQueue> Ptr;
            typedef std::shared_ptr<ICloudFilter<PointType>> InputFilterPtr;

            FilteringQueue() {}

            void AddFilter(std::shared_ptr<ICloudFilter<PointType>> filter)
            {
                m_filters.push_back(filter);
            }

            void AddFilterFunctor(typename FunctorFilter<PointType>::Functor functor)
            {
                typename FunctorFilter<PointType>::Ptr filter(new FunctorFilter<PointType>(functor));
                m_filters.push_back(filter);
            }

            typename pcl::PointCloud<PointType>::Ptr Filter(typename pcl::PointCloud<PointType>::Ptr &cloud)
            {
                typename pcl::PointCloud<PointType>::Ptr result(new pcl::PointCloud<PointType>);
                pcl::copyPointCloud(*cloud, *result);
                for (auto it = m_filters.begin(); it != m_filters.end(); ++it)
                {
                    result = (*it)->Filter(result);
                }

                return result;
            }

        private:
            std::vector<typename std::shared_ptr<ICloudFilter<PointType>>> m_filters;
    };
}

#endif // FILTERINGQUEUE_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/Filters.h
================================================
#ifndef FILTERS_H
#define FILTERS_H

#include <pcl/point_cloud.h>

#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/passthrough.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/features/normal_3d.h>

#include <pcl/surface/mls.h>
#include <Exception/HPEException.h>

#include "UI/ShowCloud.h"

namespace hpe
{
    template<typename PointT>
    typename pcl::PointCloud<PointT>::Ptr SortPoints(typename pcl::PointCloud<PointT>::Ptr cloud/*, std::function<PointT(PointT &, PointT &)> comparer*/)
    {
        typename pcl::PointCloud<PointT>::Ptr result(new pcl::PointCloud<PointT>);
        pcl::copyPointCloud(*cloud, *result);

        std::sort(result->begin(), result->end(), [](PointT a, PointT b) -> bool
        {
            float value = 100000;
            return a.y * value + a.x > b.y * value + b.x;
        });

        return result;
    }

    template<typename PointT, typename NormalT>
    typename pcl::PointCloud<NormalT>::Ptr ComputeNormals(typename pcl::PointCloud<PointT>::Ptr &cloud, int kSearch = 30, int radiusSearch = 0)
    {
        typename pcl::PointCloud<NormalT>::Ptr result(new pcl::PointCloud<NormalT>);

        typedef pcl::search::KdTree<PointT> Search;
        typename Search::Ptr search(new Search);

        pcl::NormalEstimation<PointT, NormalT> estimation;
        estimation.setSearchMethod(search);
        if (kSearch != 0)
        {
            estimation.setKSearch(kSearch);
        }
        else if (radiusSearch != 0)
        {
            estimation.setRadiusSearch(radiusSearch);
        }
        else
        {
            throw HPEException("ComputeNormals : Specify either kSearch or radiusSearch");
        }

        estimation.setInputCloud(cloud);
        estimation.compute(*result);
        return result;
    }


    template<typename PointT>
    typename pcl::PointCloud<PointT>::Ptr Voxelize(typename pcl::PointCloud<PointT>::Ptr cloud, float leafSize)
    {
        typename pcl::PointCloud<PointT>::Ptr result(new pcl::PointCloud<PointT>);

        pcl::VoxelGrid<PointT> grid;
        grid.setLeafSize(leafSize, leafSize, leafSize);
        grid.setInputCloud(cloud);
        grid.filter(*result);

        return result;
    }

    template<typename PointT>
    typename pcl::PointCloud<PointT>::Ptr RemoveOutliersByDistance(typename pcl::PointCloud<PointT>::Ptr cloud,
            int numberOfNeighborsToAnalyze, int stdThreshold)
    {
        typename pcl::PointCloud<PointT>::Ptr result(new pcl::PointCloud<PointT>);

        pcl::StatisticalOutlierRemoval<PointT> outlierRemoval;
        outlierRemoval.setInputCloud(cloud);
        outlierRemoval.setMeanK(numberOfNeighborsToAnalyze);
        outlierRemoval.setStddevMulThresh(stdThreshold);
        outlierRemoval.filter(*result);

        return result;
    }

    template<typename PointT>
    typename pcl::PointCloud<PointT>::Ptr PassThrough(typename pcl::PointCloud<PointT>::Ptr &cloud,
            float from, float to,
            std::string filterName,
            bool keepOrganzed = true)
    {
        typename pcl::PointCloud<PointT>::Ptr result(new typename pcl::PointCloud<PointT>);

        pcl::PassThrough<PointT> filter;
        filter.setFilterLimits(from, to);
        if (cloud->isOrganized())
        {
            filter.setKeepOrganized(keepOrganzed);
        }
        filter.setFilterFieldName(filterName);
        filter.setInputCloud(cloud);
        filter.filter(*result);

        return result;
    }

    template<typename PointT>
    typename pcl::PointCloud<PointT>::Ptr ResampleMLS(typename pcl::PointCloud<PointT>::Ptr &cloud, int polynomialOrder = 2, float searchRadius = 0.005)
    {
        typename pcl::PointCloud<PointT>::Ptr result(new pcl::PointCloud<PointT>);

        typename pcl::search::KdTree<PointT>::Ptr search(new pcl::search::KdTree<PointT>);
        pcl::MovingLeastSquares<PointT, PointT> mls;

        mls.setInputCloud(cloud);
        mls.setPolynomialFit(true);
        mls.setPolynomialOrder(polynomialOrder);
        mls.setSearchMethod(search);
        mls.setSearchRadius(searchRadius);

        mls.process(*result);

        return result;
    }

}

#endif // FILTERS_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/FunctorFilter.h
================================================
#ifndef FUNCTORFILTER_H
#define FUNCTORFILTER_H

#include <functional>

#include <pcl/point_cloud.h>
#include "Filter/ICloudFilter.h"

namespace hpe
{
    /**
     \class	FunctorFilter
    
     \brief	A filter that performes the operation defined inside a functor. Clearly
			the functor should conform to Functor format.
    
     \author	Sergey
     \date	8/11/2015
    
     \tparam	PointType	Type of the point type.
     */

    template<typename PointType>
    class FunctorFilter : public ICloudFilter<PointType>
    {
        public:
            typedef typename std::function<typename pcl::PointCloud<PointType>::Ptr(typename pcl::PointCloud<PointType>::Ptr &)> Functor;
            typedef std::shared_ptr<FunctorFilter> Ptr;

            FunctorFilter(Functor functor)
                : m_functor(functor)
            {

            }

            typename pcl::PointCloud<PointType>::Ptr Filter(typename pcl::PointCloud<PointType>::Ptr &cloud)
            {
                return m_functor(cloud);
            }

        private:
            Functor m_functor;

    };
}

#endif // FUNCTORFILTER_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/ICenterCloudFilter.h
================================================
#ifndef ICENTERCLOUDFILTER_H
#define ICENTERCLOUDFILTER_H

#include <Interface/IInterface.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>

namespace hpe
{
    template<typename PointType>
    class ICenterCloudFilter : public IInterface
    {
        public:
            typedef pcl::PointCloud<PointType> Cloud;

            virtual typename Cloud::Ptr Filter(typename Cloud::Ptr &cloud, float x, float y, float z) = 0;
    };
}

#endif // ICENTERCLOUDFILTER_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/ICloudFilter.h
================================================
#ifndef ICLOUDFILTER_H
#define ICLOUDFILTER_H

#include <Interface/IInterface.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>

namespace hpe
{
    /**
     \class	ICloudFilter
    
     \brief	A generic interface that takes a cloud and produces another cloud.
    
     \author	Sergey
     \date	8/11/2015
    
     \tparam	PointType	Type of the point type.
     */

    template<typename PointType>
    class ICloudFilter : public IInterface
    {
        public:
            typedef pcl::PointCloud<PointType> Cloud;

            virtual typename Cloud::Ptr Filter(typename Cloud::Ptr &cloud) = 0;
    };
}

#endif // ICLOUDFILTER_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/MovingLeastSquaresFilter.h
================================================
#pragma once

#ifndef MOVINGLEASTSQUARESFILTER_H
#define MOVINGLEASTSQUARESFILTER_H

#include <Filter/ICloudFilter.h>

#include <pcl/search/kdtree.h>
//#define PCL_NO_PRECOMPILE
#include <pcl/surface/mls.h>
//#undef PCL_NO_PRECOMPILE

namespace hpe
{
    template <class PointType>
    class MovingLeastSquaresFilter : public ICloudFilter<PointType>
    {
        public:
            typedef typename ICloudFilter<PointType>::Cloud Cloud;

            typename Cloud::Ptr Filter(typename Cloud::Ptr &cloud)
            {
                typename Cloud::Ptr result(new Cloud);

                typename pcl::search::KdTree<PointType>::Ptr search(new pcl::search::KdTree<PointType>);
                typename pcl::MovingLeastSquares<PointType, PointType> mls;

                search->setInputCloud(cloud);

                mls.setInputCloud(cloud);
                mls.setPolynomialFit(true);
                mls.setPolynomialOrder(3);
                mls.setSearchMethod(search);
                mls.setSearchRadius(0.015);
                mls.setUpsamplingMethod(mls.VOXEL_GRID_DILATION);
                mls.setDilationVoxelSize(0.001);

                mls.process(*result);

                return result;
            }
    };
}

#endif


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/GrabberBase.cpp
================================================
#include "GrabberBase.h"

#include <DataObject/RawFrames.h>
#include <pcl/common/time.h>

namespace hpe
{

    GrabberBase::GrabberBase()
    {
    }

    void GrabberBase::Start()
    {
        PreRun();

        for (auto p = m_processors.begin(); p != m_processors.end(); p++)
        {
            IProcessor::Ptr processor = *p;
            processor->Init();
        }

        m_run = true;
        while (m_run)
        {
            //TODO make thread safe
            for (auto p = m_processorsToAdd.begin(); p != m_processorsToAdd.end(); p++)
            {
                IProcessor::Ptr processor = *p;
                processor->Init();
                m_processors.push_back(processor);
            }
            m_processorsToAdd.clear();

            RawFrames::Ptr rawFrames(new RawFrames);
            bool success = GetNextFrame(rawFrames->colorFrame, rawFrames->depthFrame);
            if (success == false)
            {
                break;
            }

            IDataStorage::Ptr storage = CreateDataStorage();
            storage->Set("RawFrames", rawFrames);

            for (auto p = m_processors.begin(); p != m_processors.end(); p++)
            {
                IProcessor::Ptr processor = *p;
                processor->Process(storage);
            }
        }

        for (auto p = m_processors.begin(); p != m_processors.end(); p++)
        {
            IProcessor::Ptr processor = *p;
            processor->Cleanup();
        }
    }

    void GrabberBase::Stop()
    {
        m_run = false;
    }

    void GrabberBase::AddProcessor(IProcessor::Ptr processor)
    {
        m_processorsToAdd.push_back(processor);
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/GrabberBase.h
================================================
#pragma once

#ifndef GRABBERBASE_H
#define GRABBERBASE_H

#include <opencv2/opencv.hpp>

#include <DataObject/IDataObject.h>
#include <DataObject/IDataStorage.h>
#include <Processor/IProcessor.h>

#include <vector>

namespace hpe
{
    /**
     \class	GrabberBase
    
     \brief	A generic component to decouple technical sensor details from the 
			recognition framework. Typically it should be subclassed for any 
			sensor.

			Any grabber takes a sequence of processors to that perform a desired 
			functionality. Basically, recognition methods do not know anything about 
			processors and grabbers, they just do recognition. Grabber doesn't know 
			anything about recognition methods, but knows how to call processors,
			which in turn do not know anything about technical details of the 
			sensor, but rather accept the data from the grabber, process it,
			and pass forward.
    
     \author	Sergey
     \date	8/11/2015
     */

    class GrabberBase
    {
        public:
            GrabberBase();
            void Start();
            void Stop();
            void AddProcessor(IProcessor::Ptr processor);

        protected:
            virtual bool GetNextFrame(cv::Mat &colorFrame, cv::Mat &depthFrame) = 0;
            virtual IDataStorage::Ptr CreateDataStorage() = 0;
            virtual void PreRun() = 0;

        private:
            bool m_run;
            std::vector<IProcessor::Ptr> m_processors;
            std::vector<IProcessor::Ptr> m_processorsToAdd;
    };

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/OpenNIGrabber.cpp
================================================
#include "OpenNIGrabber.h"

#include <DataObject/MapDataStorage.h>

namespace hpe
{

    OpenNIGrabber::OpenNIGrabber(void)
    {
    }

    OpenNIGrabber::~OpenNIGrabber(void)
    {
    }

    void OpenNIGrabber::PreRun()
    {
        m_openniGrabber = std::shared_ptr<pcl::OpenNIGrabber>(new pcl::OpenNIGrabber());
        m_haveFrames = false;

        boost::function<void (const boost::shared_ptr<openni_wrapper::Image>&, const boost::shared_ptr<openni_wrapper::DepthImage>&, float)> f =
            boost::bind(&OpenNIGrabber::GrabberCallback, this, _1, _2, _3);

        m_openniGrabber->registerCallback(f);
        m_openniGrabber->start();
    }

    hpe::IDataStorage::Ptr OpenNIGrabber::CreateDataStorage()
    {
        return IDataStorage::Ptr(new MapDataStorage);
    }

    cv::Mat OpenNIGrabber::GetColorFrame(const boost::shared_ptr<openni_wrapper::Image> &img)
    {
        cv::Mat frameRGB = cv::Mat(img->getHeight(), img->getWidth(), CV_8UC3);

        img->fillRGB(frameRGB.cols, frameRGB.rows, frameRGB.data, frameRGB.step);
        cv::Mat frameBGR;
        cv::cvtColor(frameRGB, frameBGR, cv::COLOR_RGB2BGR);
        return frameBGR;
    }

    cv::Mat OpenNIGrabber::GetDepthFrame(const boost::shared_ptr<openni_wrapper::DepthImage> &depthImg)
    {
        cv::Mat frameDepth = cv::Mat(depthImg->getHeight(), depthImg->getWidth(), CV_32FC1);
        depthImg->fillDepthImage(frameDepth.cols, frameDepth.rows, (float *)frameDepth.data, frameDepth.step);
        return frameDepth;
    }

    void OpenNIGrabber::GrabberCallback(const boost::shared_ptr<openni_wrapper::Image> &color, const boost::shared_ptr<openni_wrapper::DepthImage> &depth, float c)
    {
        (void)c;

        cv::Mat colorMat = GetColorFrame(color);
        cv::Mat depthMat = GetDepthFrame(depth);

        colorMat.copyTo(m_colorFrame);
        depthMat.copyTo(m_depthFrame);

        m_haveFrames = true;
    }

    bool OpenNIGrabber::GetNextFrame(cv::Mat &colorFrame, cv::Mat &depthFrame)
    {
        while (m_haveFrames == false)
        {
            boost::this_thread::sleep(boost::posix_time::milliseconds(10));
        }
        m_haveFrames = false;

        m_colorFrame.copyTo(colorFrame);
        m_depthFrame.copyTo(depthFrame);

        return true;
    }

}


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/OpenNIGrabber.h
================================================
#pragma once
#ifndef OPENNIGRABBER_H
#define OPENNIGRABBER_H

#include <Grabber/GrabberBase.h>

#include <pcl/io/openni_grabber.h>
#include <DataObject/IDataStorage.h>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <opencv2/core/core.hpp>

namespace hpe
{

    class OpenNIGrabber : public GrabberBase
    {
        public:
            OpenNIGrabber(void);
            ~OpenNIGrabber(void);

        protected:
            void PreRun();
            hpe::IDataStorage::Ptr CreateDataStorage();
            bool GetNextFrame(cv::Mat &colorFrame, cv::Mat &depthFrame);

        private:
            cv::Mat GetColorFrame(const boost::shared_ptr<openni_wrapper::Image> &img);
            cv::Mat GetDepthFrame(const boost::shared_ptr<openni_wrapper::DepthImage> &depthImg);

            void GrabberCallback(const boost::shared_ptr<openni_wrapper::Image> &color, const boost::shared_ptr<openni_wrapper::DepthImage> &depth, float c);

            std::shared_ptr<pcl::OpenNIGrabber> m_openniGrabber;
            cv::Mat m_colorFrame;
            cv::Mat m_depthFrame;
            bool m_haveFrames;
    };

}

#endif


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/PCDGrabber.cpp
================================================
#include "PCDGrabber.h"

#include <DataObject/MapDataStorage.h>
#include <DataObject/CloudXYZRGBA.h>
#include <boost/format.hpp>
#include <pcl/io/pcd_io.h>

PCDGrabber::PCDGrabber(void)
    : m_frameNumber(0), m_endNumber(100), m_storeFolder("clouds")
{
}

PCDGrabber::PCDGrabber(int start, int end)
    : m_frameNumber(start), m_endNumber(end), m_storeFolder("clouds")
{
}

PCDGrabber::PCDGrabber(std::string folder)
    : m_frameNumber(0), m_endNumber(0), m_storeFolder(folder)
{
}

PCDGrabber::PCDGrabber(int start, int end, std::string folder)
    : m_frameNumber(start), m_endNumber(end), m_storeFolder(folder)
{
}

PCDGrabber::~PCDGrabber(void)
{
}

void PCDGrabber::PreRun()
{
    m_frameNumber = 1;
    EnumerateFiles();
}

hpe::IDataStorage::Ptr PCDGrabber::CreateDataStorage()
{
    using namespace hpe;
    IDataStorage::Ptr result(new MapDataStorage);
    CloudXYZRGBA::Ptr cloudObj(new CloudXYZRGBA(true));
    std::string path = m_pcdFiles[m_frameNumber];
    m_frameNumber += 1;
    pcl::io::loadPCDFile(path, *(cloudObj->cloud));
    result->Set("Cloud", cloudObj);

    CloudFileInfo::Ptr fileinfo(new CloudFileInfo);
    fileinfo->Filename = path;
    result->Set("FileInfo", fileinfo);

    return result;
}

bool PCDGrabber::GetNextFrame(cv::Mat &colorFrame, cv::Mat &depthFrame)
{
    return m_frameNumber < m_pcdFiles.size();
}

struct SortNumerically
{
    template <typename T>
    T st2num(const std::string &Text)
    {
        std::stringstream ss(Text);
        T result;
        return ss >> result ? result : 0;
    }

    bool operator()(const std::string &a, const std::string &b)
    {
        namespace fs = boost::filesystem;
        fs::path p1 = fs::path(a);
        fs::path p2 = fs::path(b);

        int v1 = st2num<int>(p1.stem().string());
        int v2 = st2num<int>(p2.stem().string());

        return v1 < v2;
    }
};

void PCDGrabber::EnumerateFiles()
{
    namespace fs = boost::filesystem;

    fs::path rootFolder(m_storeFolder);

    if (fs::exists(rootFolder))
    {
        if (fs::is_directory(rootFolder))
        {
            auto it = fs::directory_iterator(rootFolder);
            for (; it != fs::directory_iterator(); it++)
            {
                auto fileName = *it;
                if (fs::is_regular(fileName))
                {
                    auto path = fileName.path();
                    fs::path extension = path.extension();
                    auto filename = path.filename().string();
                    std::string p = path.string();
                    if (extension == ".pcd")
                    {
                        m_pcdFiles.push_back(p);
                    }
                }
            }
        }
    }

    SortNumerically s;
    std::sort(m_pcdFiles.begin(), m_pcdFiles.end(), s);
}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/PCDGrabber.h
================================================
#pragma once

#include <Grabber/GrabberBase.h>
#include <DataObject/IDataObject.h>

class PCDGrabber : public hpe::GrabberBase
{
    public:
        PCDGrabber(void);
        PCDGrabber(int start, int end);
        PCDGrabber(int start, int end, std::string folder);
        PCDGrabber(std::string folder);
        ~PCDGrabber(void);

        class CloudFileInfo : public hpe::IDataObject
        {
            public:
                typedef std::shared_ptr<CloudFileInfo> Ptr;
                std::string Filename;
        };

    protected:
        void PreRun();
        hpe::IDataStorage::Ptr CreateDataStorage();
        bool GetNextFrame(cv::Mat &colorFrame, cv::Mat &depthFrame);

    private:
        void EnumerateFiles();

        std::vector<std::string> m_pcdFiles;

        std::string m_storeFolder;
        int m_frameNumber;
        int m_endNumber;
};



================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/ProviderGrabber.cpp
================================================
#include "ProviderGrabber.h"

#include <Exception/HPEException.h>
#include <DataObject/MapDataStorage.h>

namespace hpe
{

    ProviderGrabber::ProviderGrabber(void)
        : m_currentFrame(0)
    {
    }


    ProviderGrabber::~ProviderGrabber(void)
    {
    }

    bool ProviderGrabber::GetNextFrame(cv::Mat &colorFrame, cv::Mat &depthFrame)
    {
        if (m_currentFrame >= m_provider->GetFrameCount())
        {
            return false;
        }

        colorFrame = m_provider->GetBgr(m_currentFrame);
        depthFrame = m_provider->GetDepth(m_currentFrame);
        m_currentFrame += 1;

        return true;
    }

    IDataStorage::Ptr ProviderGrabber::CreateDataStorage()
    {
        IDataStorage::Ptr result(new MapDataStorage);
        return result;
    }

    void ProviderGrabber::SetProvider(std::shared_ptr<ProviderType> provider)
    {
        m_provider = provider;
    }

    void ProviderGrabber::PreRun()
    {
        if (m_provider.get() == nullptr)
        {
            throw HPEException("ProviderGrabber::PreRun - m_provider == nullptr");
        }
    }

}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/ProviderGrabber.h
================================================
#pragma once

#ifndef PROVIDERGRABBER_H
#define PROVIDERGRABBER_H

#include <Grabber/GrabberBase.h>
#include <Provider/IDataProvider.h>
#include <pcl/point_types.h>

namespace hpe
{
    /**
     \class	ProviderGrabber
    
     \brief	A grabber that imitates usual grabber functionality,
			but read the frames from the the Provider, but not a 
			sensor.
    
     \author	Sergey
     \date	8/11/2015
     */

    class ProviderGrabber : public GrabberBase
    {
        public:
            typedef IDataProvider<pcl::PointXYZRGBA> ProviderType;

            ProviderGrabber(void);
            ~ProviderGrabber(void);

            void SetProvider(std::shared_ptr<ProviderType> provider);

        protected:
            bool GetNextFrame(cv::Mat &colorFrame, cv::Mat &depthFrame);
            IDataStorage::Ptr CreateDataStorage();
            void PreRun();

        private:
            std::shared_ptr<ProviderType> m_provider;
            int m_currentFrame;
    };

}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/HeadPoseEstimationFramework.vcxproj
================================================
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{A46EAD61-34BD-4EFA-B545-B8FD8C2C3BBD}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>HeadPoseEstimationFramework</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>StaticLibrary</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>StaticLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    <Import Project="..\Config\CommonProperties.props" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
    <Import Project="..\Config\CommonProperties.props" />
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
    <TargetName>$(ProjectName)_$(Configuration)</TargetName>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
    <TargetName>$(ProjectName)_$(Configuration)</TargetName>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <MultiProcessorCompilation>true</MultiProcessorCompilation>
      <MinimalRebuild>false</MinimalRebuild>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <MultiProcessorCompilation>true</MultiProcessorCompilation>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="Align\CloudMapper.cpp" />
    <ClCompile Include="Align\IncrementalHeadTemplateCreator.cpp" />
    <ClCompile Include="Align\TransformationEstimationHPE.cpp" />
    <ClCompile Include="Detector\DepthFrameDetector\csvMat.cpp" />
    <ClCompile Include="Detector\DepthFrameDetector\DepthDetector.cpp" />
    <ClCompile Include="Detector\DepthFrameDetector\LeafNode.cpp" />
    <ClCompile Include="Detector\DepthFrameDetector\localFunctions.cpp" />
    <ClCompile Include="Detector\DepthFrameDetector\Tree.cpp" />
    <ClCompile Include="FacialExpressions\ferLocalFunctions.cpp" />
    <ClCompile Include="Features\Calculator\CylinderOptimizedFeatureCalculator.cpp" />
    <ClCompile Include="Features\Sampler\CylinderSampler.cpp" />
    <ClCompile Include="Grabber\PCDGrabber.cpp" />
    <ClCompile Include="Helpers\HpeHelpers.cpp" />
    <ClCompile Include="Processor\DetectorProcessor.cpp" />
    <ClCompile Include="Processor\FacialExpressionsProcessor.cpp" />
    <ClCompile Include="Processor\FilterProcessor.cpp" />
    <ClCompile Include="Processor\SaveCloudProcessor.cpp" />
    <ClCompile Include="Processor\TrackingProcessor.cpp" />
    <ClCompile Include="WindowsOnly\Processor\KinectSDKConverterProcessor.cpp" />
    <ClCompile Include="WindowsOnly\Grabber\KinectSDKGrabber.cpp" />
    <ClCompile Include="Processor\DepthPreprocessingProcessor.cpp" />
    <ClCompile Include="Processor\HeadExtractionProcessor.cpp" />
    <ClCompile Include="Processor\ConverterProcessor.cpp" />
    <ClCompile Include="DataObject\MapDataStorage.cpp" />
    <ClCompile Include="Converter\KinectDataConverter.cpp" />
    <ClCompile Include="Exception\HPEException.cpp" />
    <ClCompile Include="Grabber\GrabberBase.cpp" />
    <ClCompile Include="Grabber\ProviderGrabber.cpp" />
    <ClCompile Include="Settings\HPESettings.cpp" />
    <ClCompile Include="Processor\TemplateCreatorProcessor.cpp" />
    <ClCompile Include="Processor\ShowCloudProcessor.cpp" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="Align\CloudMapper.h" />
    <ClInclude Include="Align\IHeadTemplateCreator.h" />
    <ClInclude Include="Align\TemplateAlignment.h" />
    <ClInclude Include="Align\TransformationEstimationHPE.h" />
    <ClInclude Include="DataObject\CloudXYZRGBA.h" />
    <ClInclude Include="Align\IncrementalHeadTemplateCreator.h" />
    <ClInclude Include="DataObject\HeadPoseInfo.h" />
    <ClInclude Include="DataObject\LandmarksObject.h" />
    <ClInclude Include="Detector\DepthFrameDetector\csvMat.h" />
    <ClInclude Include="Detector\DepthFrameDetector\DepthDetector.h" />
    <ClInclude Include="Detector\DepthFrameDetector\LeafNode.h" />
    <ClInclude Include="Detector\DepthFrameDetector\localFunctions.h" />
    <ClInclude Include="Detector\DepthFrameDetector\Tree.h" />
    <ClInclude Include="FacialExpressions\ferLocalFunctions.h" />
    <ClInclude Include="Features\Calculator\CylinderOptimizedFeatureCalculator.h" />
    <ClInclude Include="Features\Sampler\CylinderSampler.h" />
    <ClInclude Include="Grabber\PCDGrabber.h" />
    <ClInclude Include="Filter\MovingLeastSquaresFilter.h" />
    <ClInclude Include="Helpers\HpeHelpers.h" />
    <ClInclude Include="Processor\DetectorProcessor.h" />
    <ClInclude Include="Processor\FacialExpressionsProcessor.h" />
    <ClInclude Include="Processor\FilterProcessor.h" />
    <ClInclude Include="Processor\SaveCloudProcessor.h" />
    <ClInclude Include="Processor\TrackingProcessor.h" />
    <ClInclude Include="rapidjson\allocators.h" />
    <ClInclude Include="rapidjson\document.h" />
    <ClInclude Include="rapidjson\encodedstream.h" />
    <ClInclude Include="rapidjson\encodings.h" />
    <ClInclude Include="rapidjson\error\en.h" />
    <ClInclude Include="rapidjson\error\error.h" />
    <ClInclude Include="rapidjson\filereadstream.h" />
    <ClInclude Include="rapidjson\filestream.h" />
    <ClInclude Include="rapidjson\filewritestream.h" />
    <ClInclude Include="rapidjson\internal\dtoa.h" />
    <ClInclude Include="rapidjson\internal\itoa.h" />
    <ClInclude Include="rapidjson\internal\meta.h" />
    <ClInclude Include="rapidjson\internal\pow10.h" />
    <ClInclude Include="rapidjson\internal\stack.h" />
    <ClInclude Include="rapidjson\internal\strfunc.h" />
    <ClInclude Include="rapidjson\memorybuffer.h" />
    <ClInclude Include="rapidjson\memorystream.h" />
    <ClInclude Include="rapidjson\msinttypes\inttypes.h" />
    <ClInclude Include="rapidjson\msinttypes\stdint.h" />
    <ClInclude Include="rapidjson\prettywriter.h" />
    <ClInclude Include="rapidjson\rapidjson.h" />
    <ClInclude Include="rapidjson\reader.h" />
    <ClInclude Include="rapidjson\stringbuffer.h" />
    <ClInclude Include="rapidjson\writer.h" />
    <ClInclude Include="WindowsOnly\Processor\KinectSDKConverterProcessor.h" />
    <ClInclude Include="WindowsOnly\Grabber\KinectSDKGrabber.h" />
    <ClInclude Include="Processor\DepthPreprocessingProcessor.h" />
    <ClInclude Include="Processor\HeadExtractionProcessor.h" />
    <ClInclude Include="Processor\ConverterProcessor.h" />
    <ClInclude Include="DataObject\IDataObject.h" />
    <ClInclude Include="DataObject\IDataStorage.h" />
    <ClInclude Include="DataObject\MapDataStorage.h" />
    <ClInclude Include="DataObject\RawFrames.h" />
    <ClInclude Include="Common.h" />
    <ClInclude Include="Converter\IDataConverter.h" />
    <ClInclude Include="Converter\KinectDataConverter.h" />
    <ClInclude Include="DataFilter\IDataFilter.h" />
    <ClInclude Include="Descriptors2D\IDescriptor.h" />
    <ClInclude Include="Features\Calculator\FeatureCalculatorBase.h" />
    <ClInclude Include="Features\DepthProjectionFeature.h" />
    <ClInclude Include="Exception\HPEException.h" />
    <ClInclude Include="Features\Calculator\FeatureCalculator.h" />
    <ClInclude Include="Features\IFeature.h" />
    <ClInclude Include="Features\Calculator\IFeatureCalculator.h" />
    <ClInclude Include="Features\Sampler\IPatchSampler.h" />
    <ClInclude Include="Features\ProjectionFeatureBase.h" />
    <ClInclude Include="Filter\BoxFilter.h" />
    <ClInclude Include="Filter\CenteredBoxFilter.h" />
    <ClInclude Include="Filter\FilteringQueue.h" />
    <ClInclude Include="Filter\Filters.h" />
    <ClInclude Include="Filter\FunctorFilter.h" />
    <ClInclude Include="Filter\ICenterCloudFilter.h" />
    <ClInclude Include="Filter\ICloudFilter.h" />
    <ClInclude Include="Grabber\GrabberBase.h" />
    <ClInclude Include="GraphicalObjects\IGraphicalObject.h" />
    <ClInclude Include="Features\Sampler\GridSampler.h" />
    <ClInclude Include="Features\RGBProjectionFeature.h" />
    <ClInclude Include="Processor\IProcessor.h" />
    <ClInclude Include="Grabber\ProviderGrabber.h" />
    <ClInclude Include="Settings\HPESettings.h" />
    <ClInclude Include="Interface\IInterface.h" />
    <ClInclude Include="Landmarks.h" />
    <ClInclude Include="Provider\IDataProvider.h" />
    <ClInclude Include="Processor\ShowCloudProcessor.h" />
    <ClInclude Include="SurfaceReconstruction\ISurfaceReconstructor.h" />
    <ClInclude Include="Processor\TemplateCreatorProcessor.h" />
    <ClInclude Include="Tracker\ICPTemplateTracker.h" />
    <ClInclude Include="UI\PointPicker.h" />
    <ClInclude Include="UI\ShowCloud.h" />
    <ClInclude Include="UI\ShowMesh.h" />
    <ClInclude Include="UI\VisualizerCommon.h" />
    <ClInclude Include="vtkBindings\MarchingCubes.h" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Helpers/HpeHelpers.cpp
================================================
#include "HpeHelpers.h"



namespace hpe
{
    Eigen::Vector3f VectorToEulerAngles(Eigen::Vector3f v)
    {
        Eigen::Vector3f normed = v / v.norm();
        float x = normed(0);
        float y = normed(1);
        float z = normed(2);

        Eigen::Vector3f result;
        result(0) = std::atan2(z, x); // yaw
        result(1) = std::atan2(y, z); // tilt
        result(2) = std::atan(y / x); // roll
        return result;
    }

    Eigen::Vector3f EulerAnglesToVector(double yaw, double tilt, bool inDegrees)
    {
        if (inDegrees)
        {
            yaw = yaw / 180 * M_PI;
            tilt = tilt / 180 * M_PI;
        }

        Eigen::Vector3f newVector;
        double yawTan = std::tan(yaw);
        double tiltTan = std::tan(tilt);
        if (yawTan != 0)
        {
            newVector << 1 / yawTan, -tiltTan, 1;
        }
        else
        {
            newVector << 1000, -tiltTan, 1;
        }

        return newVector / newVector.norm();
    }

    cv::Point2f MeanPoint(std::vector<cv::Point2f> points)
    {
        cv::Point2f res(0, 0);
        for (auto pt = points.begin(); pt != points.end(); pt++)
        {
            res.x += pt->x;
            res.y += pt->y;
        }

        if (points.size() != 0)
        {
            res.x /= points.size();
            res.y /= points.size();
        }

        return res;
    }






}

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Helpers/HpeHelpers.h
================================================
#pragma once

#ifndef HPEHELPERS_H
#define HPEHELPERS_H

#include <pcl/common/common.h>
#include <pcl/point_cloud.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d.h>
#include <opencv2/opencv.hpp>

namespace hpe
{
    Eigen::Vector3f VectorToEulerAngles(Eigen::Vector3f v);

    Eigen::Vector3f EulerAnglesToVector(double yaw, double tilt, bool inDegrees = true);

    template <typename PointType>
    Eigen::Vector3f GetNormal(typename pcl::PointCloud<PointType>::Ptr cloud, int noseInCloud)
    {
        Eigen::Vector3f result;

        pcl::search::KdTree<PointType>::Ptr search(new pcl::search::KdTree<PointType>);

        pcl::IndicesPtr idx(new std::vector<int>);
        idx->push_back(noseInCloud);

        pcl::NormalEstimation<PointType, pcl::Normal> ne;
        ne.setInputCloud(cloud);
        ne.setIndices(idx);
        ne.setKSearch(50);
        ne.setSearchMethod(search);

        pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud <pcl::Normal>);
        ne.compute(*normals);
        result = normals->points[0].getNormalVector3fMap();

        return result;
    }

    cv::Point2f MeanPoint(std::vector<cv::Point2f> points);
}

#endif

================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Interface/IInterface.h
================================================
#pragma once

#ifndef IINTERFACE_H
#define IINTERFACE_H

namespace hpe
{
    class IInterface
    {
        public:
            virtual ~IInterface() {}
    };
}

#endif // IINTERFACE_H


================================================
FILE: FaceCept3D/HeadPoseEstimationFramework/Landmarks.h
================================================
#ifndef LANDMARKS_H
#define LANDMARKS_H

#include <fstream>
#include <ostream>
#include <istream>
#include <string>
#include <algorithm>

#include <boost/algorithm/string/split.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/assign.hpp>
#include <Eigen/Eigen>

#include <Common.h>

#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/search/kdtree.h>

namespace hpe
{
    using namespace boost::assign;

    template <typename PointType>
    void SaveLandmarks(typename Common<PointType>::Landmarks landmarks, std::string filename)
    {
        std::ofstream stream(filename);

        std::for_each(landmarks.begin(), landmarks.end(), [&](typename Common<PointType>::Landmarks::value_type l)
        {
            stream << l.index << " " << l.point.x << " " << l.point.y << " " << l.point.z << std::endl;
        });
    }

    template <typename PointType>
    typename Common<PointType>::Landmarks LoadLandmarks(std::string filename)
    {
        typename Common<PointType>::Landmarks landmarks;
        std::ifstream istream(filename.c_str());

        std::string line;
        while (std::getline(istream, line))
        {
            std::vector<std::string> values;
            boost::split(values, line, boost::is_any_of(" \t"), boost::token_compress_on);
            typename Common<PointType>::Landmark l;
            if (values[0] != "n")
            {
                l.index = boost::lexical_cast<int>(values[0]);
                l.point.x = boost::lexical_cast<float>(values[1]);
                l.point.y = boost::lexical_cast<float>(values[2]);
                l.point.z = boost::lexical_cast<float>(values[3]);
                landmarks.push_back(l);
            }
        }
        return landmarks;
    }

    template <typename PointType>
    typename Common<PointType>::Landmarks ResampleLandmarks(typename Common<PointType>::Landmarks &oldLandmarks,
            typename pcl::PointCloud<PointType>::Ptr &cloudToResample)
    {
        typename Common<PointType>::Landmarks newLandmarks;
        for (int i = 0; i < oldLandmarks.size(); i++)
        {
            typename Common<PointType>::Landmark l;
            auto oldLandmark = oldLandmarks.at(i);
            l.index = oldLandmark.index;
            l.point = cloudToResample->at(l.index);
            newLandmarks.push_back(l);
        }

        return newLandmarks;
    }

    template<typename PointType>
    typename Common<PointType>::Landmarks ResampleLandmarksByPosition(typename Common<PointType>::Landmarks &oldLandmarks, typename pcl::PointCloud<PointType>::Ptr &cloudToResample)
    {
        pcl::search::KdTree<PointType> tree;
        tree.setInputCloud(cloudToResample);

        typename Common<PointType>::Landmarks newLandmarks;

        for (int i = 0; i < oldLandmarks.size(); i += 1)
        {
            std::vector<int> indices;
            std::vector<float> distances;
            tree.nearestKSearch(oldLandmarks[i].point, 1, indices, distances);

            typename Common<PointType>::Landmark newLandmark;
            newLandmark.index = indices[0];
            newLandmark.point = cloudToResample->points[newLandmark.index];

            newLandmarks.push_back(newLandmark);
        }

        return newLandmarks;
    }


    template <typename PointType>
    PointType MeanLandmark(type
Download .txt
gitextract_pxarii44/

├── .gitignore
├── FaceCept3D/
│   ├── 3dheadposeestimation.sln
│   ├── CMakeLists.txt
│   ├── Config/
│   │   ├── CommonProperties.props
│   │   ├── CommonPropertiesLibsDebug.props
│   │   └── CommonPropertiesLibsRelease.props
│   ├── HeadPoseEstimationFramework/
│   │   ├── Align/
│   │   │   ├── CloudMapper.cpp
│   │   │   ├── CloudMapper.h
│   │   │   ├── IHeadTemplateCreator.h
│   │   │   ├── IncrementalHeadTemplateCreator.cpp
│   │   │   ├── IncrementalHeadTemplateCreator.h
│   │   │   ├── TransformationEstimationHPE.cpp
│   │   │   └── TransformationEstimationHPE.h
│   │   ├── CMakeLists.txt
│   │   ├── Common.h
│   │   ├── Converter/
│   │   │   ├── IDataConverter.h
│   │   │   ├── KinectDataConverter.cpp
│   │   │   └── KinectDataConverter.h
│   │   ├── DataFilter/
│   │   │   └── IDataFilter.h
│   │   ├── DataObject/
│   │   │   ├── CloudXYZRGBA.h
│   │   │   ├── HeadPoseInfo.h
│   │   │   ├── IDataObject.h
│   │   │   ├── IDataStorage.h
│   │   │   ├── LandmarksObject.h
│   │   │   ├── MapDataStorage.cpp
│   │   │   ├── MapDataStorage.h
│   │   │   └── RawFrames.h
│   │   ├── Detector/
│   │   │   └── DepthFrameDetector/
│   │   │       ├── DepthDetector.cpp
│   │   │       ├── DepthDetector.h
│   │   │       ├── LeafNode.cpp
│   │   │       ├── LeafNode.h
│   │   │       ├── Tree.cpp
│   │   │       ├── Tree.h
│   │   │       ├── csvMat.cpp
│   │   │       ├── csvMat.h
│   │   │       ├── localFunctions.cpp
│   │   │       └── localFunctions.h
│   │   ├── Exception/
│   │   │   ├── HPEException.cpp
│   │   │   └── HPEException.h
│   │   ├── FacialExpressions/
│   │   │   ├── ferLocalFunctions.cpp
│   │   │   └── ferLocalFunctions.h
│   │   ├── Features/
│   │   │   ├── Calculator/
│   │   │   │   ├── CylinderOptimizedFeatureCalculator.cpp
│   │   │   │   ├── CylinderOptimizedFeatureCalculator.h
│   │   │   │   ├── FeatureCalculatorBase.h
│   │   │   │   └── IFeatureCalculator.h
│   │   │   ├── IFeature.h
│   │   │   └── Sampler/
│   │   │       ├── CylinderSampler.cpp
│   │   │       ├── CylinderSampler.h
│   │   │       └── IPatchSampler.h
│   │   ├── Filter/
│   │   │   ├── BoxFilter.h
│   │   │   ├── CenteredBoxFilter.h
│   │   │   ├── FilteringQueue.h
│   │   │   ├── Filters.h
│   │   │   ├── FunctorFilter.h
│   │   │   ├── ICenterCloudFilter.h
│   │   │   ├── ICloudFilter.h
│   │   │   └── MovingLeastSquaresFilter.h
│   │   ├── Grabber/
│   │   │   ├── GrabberBase.cpp
│   │   │   ├── GrabberBase.h
│   │   │   ├── OpenNIGrabber.cpp
│   │   │   ├── OpenNIGrabber.h
│   │   │   ├── PCDGrabber.cpp
│   │   │   ├── PCDGrabber.h
│   │   │   ├── ProviderGrabber.cpp
│   │   │   └── ProviderGrabber.h
│   │   ├── HeadPoseEstimationFramework.vcxproj
│   │   ├── Helpers/
│   │   │   ├── HpeHelpers.cpp
│   │   │   └── HpeHelpers.h
│   │   ├── Interface/
│   │   │   └── IInterface.h
│   │   ├── Landmarks.h
│   │   ├── Processor/
│   │   │   ├── ConverterProcessor.cpp
│   │   │   ├── ConverterProcessor.h
│   │   │   ├── DepthPreprocessingProcessor.cpp
│   │   │   ├── DepthPreprocessingProcessor.h
│   │   │   ├── DetectorProcessor.cpp
│   │   │   ├── DetectorProcessor.h
│   │   │   ├── FacialExpressionsProcessor.cpp
│   │   │   ├── FacialExpressionsProcessor.h
│   │   │   ├── FilterProcessor.cpp
│   │   │   ├── FilterProcessor.h
│   │   │   ├── HeadExtractionProcessor.cpp
│   │   │   ├── HeadExtractionProcessor.h
│   │   │   ├── IProcessor.h
│   │   │   ├── SaveCloudProcessor.cpp
│   │   │   ├── SaveCloudProcessor.h
│   │   │   ├── ShowCloudProcessor.cpp
│   │   │   ├── ShowCloudProcessor.h
│   │   │   ├── TemplateCreatorProcessor.cpp
│   │   │   ├── TemplateCreatorProcessor.h
│   │   │   ├── TrackingProcessor.cpp
│   │   │   └── TrackingProcessor.h
│   │   ├── Provider/
│   │   │   ├── IDataProvider.h
│   │   │   ├── RawDataProvider.cpp
│   │   │   └── RawDataProvider.h
│   │   ├── Settings/
│   │   │   ├── HPESettings.cpp
│   │   │   └── HPESettings.h
│   │   ├── Tracker/
│   │   │   └── ICPTemplateTracker.h
│   │   ├── UI/
│   │   │   ├── PointPicker.h
│   │   │   ├── ShowCloud.h
│   │   │   ├── ShowMesh.h
│   │   │   └── VisualizerCommon.h
│   │   └── WindowsOnly/
│   │       ├── Grabber/
│   │       │   ├── KinectSDKGrabber.cpp
│   │       │   └── KinectSDKGrabber.h
│   │       └── Processor/
│   │           ├── KinectSDKConverterProcessor.cpp
│   │           └── KinectSDKConverterProcessor.h
│   ├── TemplateCreator/
│   │   ├── CMakeLists.txt
│   │   ├── TemplateCreator.cpp
│   │   ├── TemplateCreator.vcxproj
│   │   ├── UIProcessor.cpp
│   │   ├── UIProcessor.h
│   │   ├── settings.ini
│   │   ├── stdafx.cpp
│   │   └── stdafx.h
│   └── TemplateTracker/
│       ├── ShowTwoCloudsProcessor.cpp
│       ├── ShowTwoCloudsProcessor.h
│       ├── TemplateTracker.cpp
│       ├── TemplateTracker.vcxproj
│       ├── UIProcessor.cpp
│       ├── UIProcessor.h
│       ├── VisuilizeProcessor.cpp
│       ├── VisuilizeProcessor.h
│       ├── VoxelizeProcessor.cpp
│       ├── VoxelizeProcessor.h
│       ├── settings.ini
│       ├── stdafx.cpp
│       └── stdafx.h
├── LICENSE
└── README.md
Download .txt
SYMBOL INDEX (139 symbols across 102 files)

FILE: FaceCept3D/HeadPoseEstimationFramework/Align/CloudMapper.cpp
  type hpe (line 35) | namespace hpe
    function CalculateDistance (line 37) | float CalculateDistance(pcl::PointXYZRGBA &p1, pcl::PointXYZRGBA &p2)

FILE: FaceCept3D/HeadPoseEstimationFramework/Align/CloudMapper.h
  function namespace (line 17) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Align/IHeadTemplateCreator.h
  function namespace (line 8) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Align/IncrementalHeadTemplateCreator.cpp
  type hpe (line 7) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Align/IncrementalHeadTemplateCreator.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Align/TransformationEstimationHPE.h
  function namespace (line 8) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Common.h
  function namespace (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Converter/IDataConverter.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Converter/KinectDataConverter.cpp
  type hpe (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Converter/KinectDataConverter.h
  function namespace (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/DataFilter/IDataFilter.h
  function namespace (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/CloudXYZRGBA.h
  function namespace (line 11) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/HeadPoseInfo.h
  function namespace (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/IDataObject.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/IDataStorage.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/LandmarksObject.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/MapDataStorage.cpp
  type hpe (line 3) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/MapDataStorage.h
  function namespace (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/DataObject/RawFrames.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/DepthDetector.cpp
  type hpe (line 5) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/DepthDetector.h
  function namespace (line 11) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/LeafNode.cpp
  type hpe (line 13) | namespace hpe
    function evaluatePackedTree (line 17) | void evaluatePackedTree(Mat patchInt, Mat maskInt, Mat treeMat, Mat tr...

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/LeafNode.h
  function namespace (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/Tree.cpp
  type hpe (line 16) | namespace hpe
    function Tree (line 19) | Tree readTree(string csvRootName, int treeIdx)

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/Tree.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/csvMat.cpp
  type hpe (line 15) | namespace hpe
    function Mat (line 18) | Mat readCSVMat(string csvFrameName, int lin, int col)

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/csvMat.h
  function namespace (line 15) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/localFunctions.cpp
  type hpe (line 16) | namespace hpe
    function loadConfig (line 19) | void loadConfig(std::string filename, paramList *p, bool verbose)
    function Rect (line 81) | Rect getBoundingBox(const Mat &im3D, paramList p) {
    function computeNorm (line 125) | double computeNorm(vector<double> vec1, vector<double> vec2)
    function computeMean (line 140) | double computeMean(vector<double> vec)
    function Mat (line 150) | Mat meanShift(Mat dataPts, double bandWidth, int *maxClustPointer)
    function headPoseInfo (line 280) | headPoseInfo estimateHeadAngles(Mat depthFrame, vector<Tree> cascade, ...

FILE: FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/localFunctions.h
  function namespace (line 15) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Exception/HPEException.h
  function class (line 6) | class HPEException : public std::exception

FILE: FaceCept3D/HeadPoseEstimationFramework/FacialExpressions/ferLocalFunctions.cpp
  type fer (line 16) | namespace fer
    function to_string (line 22) | std::string to_string(int val)
    function get_all_files_names_within_folder (line 29) | vector<string> get_all_files_names_within_folder(string folder)
    function Mat (line 49) | Mat RV_readCSVMat(string csvFrameName, int lin, int col)
    function RV_readParamList (line 73) | void RV_readParamList(const string foldername, paramList *p)
    function RV_readAllForests (line 141) | vector<vector<randomTree>> RV_readAllForests(string forestDir, paramLi...
    function RV_computeHist (line 166) | vector<double> RV_computeHist(vector<double> vec, int noBins)
    function RV_testForest (line 179) | vector<double> RV_testForest(Mat localData, vector<randomTree> &localF...
    function Rect (line 205) | Rect RV_getBoundingBox(const Mat &im3D, paramList p) {
    function RV_computeNorm (line 249) | double RV_computeNorm(vector<double> vec1, vector<double> vec2)
    function RV_computeMean (line 264) | double RV_computeMean(vector<double> vec)
    function Mat (line 274) | Mat meanShift(Mat dataPts, double bandWidth, int *maxClustPointer)
    function Mat (line 404) | Mat RV_preprocessDepthFrame(Mat frame)
    function RV_featExtractionSingleFrame (line 450) | void RV_featExtractionSingleFrame(Mat frame, paramList params, vector<...
    function Mat (line 530) | Mat RV_computeDiffFeats(vector<Mat> imageInt, vector<Mat> maskInt, Mat...
    function RV_channelsExtractionSingleFrame (line 595) | vector<Mat> RV_channelsExtractionSingleFrame(Mat frame, paramList params)
    function RV_gaussPdf (line 677) | double RV_gaussPdf(double x, double mu, double sigma)
    function RV_imshow (line 693) | int RV_imshow(string windowName, Mat img)
    function Mat (line 703) | Mat RV_lbp(const Mat &src)

FILE: FaceCept3D/HeadPoseEstimationFramework/FacialExpressions/ferLocalFunctions.h
  function namespace (line 11) | namespace fer

FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/CylinderOptimizedFeatureCalculator.cpp
  type hpe (line 3) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/CylinderOptimizedFeatureCalculator.h
  function namespace (line 16) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/FeatureCalculatorBase.h
  function namespace (line 20) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/IFeatureCalculator.h
  function namespace (line 8) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Features/IFeature.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Sampler/CylinderSampler.cpp
  type hpe (line 21) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Sampler/CylinderSampler.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Features/Sampler/IPatchSampler.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/BoxFilter.h
  function namespace (line 7) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/CenteredBoxFilter.h
  function namespace (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/FilteringQueue.h
  function namespace (line 16) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/Filters.h
  function namespace (line 16) | namespace hpe
  type pcl (line 38) | typedef pcl::search::KdTree<PointT> Search;

FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/FunctorFilter.h
  function namespace (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/ICenterCloudFilter.h
  function namespace (line 8) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/ICloudFilter.h
  function namespace (line 8) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Filter/MovingLeastSquaresFilter.h
  function namespace (line 13) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/GrabberBase.cpp
  type hpe (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/GrabberBase.h
  function namespace (line 14) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/OpenNIGrabber.cpp
  type hpe (line 5) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/OpenNIGrabber.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/PCDGrabber.cpp
  type SortNumerically (line 60) | struct SortNumerically
    method T (line 63) | T st2num(const std::string &Text)

FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/PCDGrabber.h
  function class (line 6) | class PCDGrabber : public hpe::GrabberBase

FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/ProviderGrabber.cpp
  type hpe (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Grabber/ProviderGrabber.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Helpers/HpeHelpers.cpp
  type hpe (line 5) | namespace hpe
    function VectorToEulerAngles (line 7) | Eigen::Vector3f VectorToEulerAngles(Eigen::Vector3f v)
    function EulerAnglesToVector (line 21) | Eigen::Vector3f EulerAnglesToVector(double yaw, double tilt, bool inDe...
    function MeanPoint (line 44) | cv::Point2f MeanPoint(std::vector<cv::Point2f> points)

FILE: FaceCept3D/HeadPoseEstimationFramework/Helpers/HpeHelpers.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Interface/IInterface.h
  function namespace (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Landmarks.h
  function namespace (line 22) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/ConverterProcessor.cpp
  type hpe (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/ConverterProcessor.h
  function namespace (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/DepthPreprocessingProcessor.cpp
  type hpe (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/DepthPreprocessingProcessor.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/DetectorProcessor.cpp
  type hpe (line 8) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/DetectorProcessor.h
  function namespace (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/FacialExpressionsProcessor.cpp
  type hpe (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/FacialExpressionsProcessor.h
  function namespace (line 13) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/FilterProcessor.cpp
  type hpe (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/FilterProcessor.h
  function namespace (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/HeadExtractionProcessor.cpp
  type hpe (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/HeadExtractionProcessor.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/IProcessor.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/SaveCloudProcessor.cpp
  type hpe (line 14) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/SaveCloudProcessor.h
  function namespace (line 16) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/ShowCloudProcessor.cpp
  type hpe (line 6) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/ShowCloudProcessor.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/TemplateCreatorProcessor.cpp
  type hpe (line 5) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/TemplateCreatorProcessor.h
  function namespace (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/TrackingProcessor.cpp
  type hpe (line 25) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Processor/TrackingProcessor.h
  function namespace (line 17) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Provider/IDataProvider.h
  function namespace (line 11) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Provider/RawDataProvider.cpp
  type hpe (line 10) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Provider/RawDataProvider.h
  function namespace (line 11) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Settings/HPESettings.cpp
  type hpe (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Settings/HPESettings.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/Tracker/ICPTemplateTracker.h
  function namespace (line 17) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/UI/PointPicker.h
  function namespace (line 23) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/UI/ShowCloud.h
  function namespace (line 20) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/UI/ShowMesh.h
  function namespace (line 9) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/UI/VisualizerCommon.h
  function namespace (line 15) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/WindowsOnly/Grabber/KinectSDKGrabber.cpp
  type hpe (line 8) | namespace hpe
    function HRESULT (line 61) | HRESULT KinectSDKGrabber::CreateFirstConnected()
    function HRESULT (line 144) | HRESULT KinectSDKGrabber::ProcessDepth(float *buffer)
    function HRESULT (line 230) | HRESULT KinectSDKGrabber::ProcessColor(cv::Mat &mat)
    function INuiCoordinateMapper (line 282) | INuiCoordinateMapper *KinectSDKGrabber::GetCoordinateMapper()

FILE: FaceCept3D/HeadPoseEstimationFramework/WindowsOnly/Grabber/KinectSDKGrabber.h
  function namespace (line 12) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/WindowsOnly/Processor/KinectSDKConverterProcessor.cpp
  type hpe (line 14) | namespace hpe

FILE: FaceCept3D/HeadPoseEstimationFramework/WindowsOnly/Processor/KinectSDKConverterProcessor.h
  function namespace (line 13) | namespace hpe

FILE: FaceCept3D/TemplateCreator/TemplateCreator.cpp
  function main (line 21) | int main(int argc, char *argv[])

FILE: FaceCept3D/TemplateCreator/UIProcessor.h
  function class (line 11) | class UIProcessor : public hpe::ShowCloudProcessor

FILE: FaceCept3D/TemplateTracker/ShowTwoCloudsProcessor.h
  function class (line 9) | class ShowTwoCloudsProcessor : public hpe::IProcessor

FILE: FaceCept3D/TemplateTracker/TemplateTracker.cpp
  function main (line 28) | int main(int argc, char *argv[])

FILE: FaceCept3D/TemplateTracker/UIProcessor.h
  function class (line 10) | class UIProcessor : public hpe::IProcessor

FILE: FaceCept3D/TemplateTracker/VisuilizeProcessor.h
  function class (line 10) | class VisuilizeProcessor : public hpe::IProcessor

FILE: FaceCept3D/TemplateTracker/VoxelizeProcessor.h
  function class (line 5) | class VoxelizeProcessor : public hpe::IProcessor
Condensed preview — 128 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (364K chars).
[
  {
    "path": ".gitignore",
    "chars": 118,
    "preview": "*.suo\n*.sdf\n*.user\n*.opensdf\n*.txt\n*.idea\n!CMakeLists.txt\n\nbuild\nipch\nDebug\nRelease\nx64\ndata/DetectorData\ndata/FERData"
  },
  {
    "path": "FaceCept3D/3dheadposeestimation.sln",
    "chars": 4023,
    "preview": "\nMicrosoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio 2013\nVisualStudioVersion = 12.0.21005.1\nMi"
  },
  {
    "path": "FaceCept3D/CMakeLists.txt",
    "chars": 117,
    "preview": "cmake_minimum_required(VERSION 2.8)\n\nadd_subdirectory(HeadPoseEstimationFramework)\nadd_subdirectory(TemplateCreator)\n"
  },
  {
    "path": "FaceCept3D/Config/CommonProperties.props",
    "chars": 1028,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuil"
  },
  {
    "path": "FaceCept3D/Config/CommonPropertiesLibsDebug.props",
    "chars": 4187,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuil"
  },
  {
    "path": "FaceCept3D/Config/CommonPropertiesLibsRelease.props",
    "chars": 3835,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuil"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Align/CloudMapper.cpp",
    "chars": 17095,
    "preview": "#include \"CloudMapper.h\"\n\n#include <pcl/common/common.h>\n\n#include <pcl/registration/registration.h>\n\n#include <pcl/regi"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Align/CloudMapper.h",
    "chars": 4636,
    "preview": "#ifndef CLOUDMAPPER_H\n#define CLOUDMAPPER_H\n\n#include <memory>\n\n\n#include <vector>\n#include <pcl/point_types.h>\n#include"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Align/IHeadTemplateCreator.h",
    "chars": 375,
    "preview": "#ifndef IHEADTEMPLATECREATOR_H\n#define IHEADTEMPLATECREATOR_H\n\n#include <pcl/point_cloud.h>\n\n#include <Interface/IInterf"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Align/IncrementalHeadTemplateCreator.cpp",
    "chars": 1869,
    "preview": "#include \"IncrementalHeadTemplateCreator.h\"\n#include <Filter/Filters.h>\n#include <pcl/common/io.h>\n#include <pcl/common/"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Align/IncrementalHeadTemplateCreator.h",
    "chars": 1101,
    "preview": "#pragma once\n\n#ifndef INCREMENTALHEADTEMPLATECREATOR_H\n#define INCREMENTALHEADTEMPLATECREATOR_H\n\n#include <Align/IHeadTe"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Align/TransformationEstimationHPE.cpp",
    "chars": 41,
    "preview": "#include \"TransformationEstimationHPE.h\"\n"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Align/TransformationEstimationHPE.h",
    "chars": 3983,
    "preview": "#ifndef TRANSFORMATIONESTIMATION_H\n#define TRANSFORMATIONESTIMATION_H\n\n#include <pcl/point_cloud.h>\n\n#include <pcl/regis"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/CMakeLists.txt",
    "chars": 673,
    "preview": "cmake_minimum_required(VERSION 2.8)\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11\")\n\nproject(HeadPoseEstimationFra"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Common.h",
    "chars": 604,
    "preview": "#pragma once\n\n#ifndef COMMON_H\n#define COMMON_H\n\n#include <vector>\n#include <list>\n\nnamespace hpe\n{\n    template <typena"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Converter/IDataConverter.h",
    "chars": 412,
    "preview": "#ifndef IDATACONVERTER_H\n#define IDATACONVERTER_H\n\n#include <pcl/point_cloud.h>\n#include <pcl/point_types.h>\n#include <o"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Converter/KinectDataConverter.cpp",
    "chars": 3258,
    "preview": "#include \"KinectDataConverter.h\"\n\n#include <boost/math/special_functions/fpclassify.hpp>\n#include <boost/math/special_fu"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Converter/KinectDataConverter.h",
    "chars": 827,
    "preview": "#ifndef KINECTDATACONVERTER_H\n#define KINECTDATACONVERTER_H\n\n#include <Converter/IDataConverter.h>\n\nnamespace hpe\n{\n    "
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/DataFilter/IDataFilter.h",
    "chars": 284,
    "preview": "#ifndef IDATAFILTER_H\n#define IDATAFILTER_H\n\n#include \"Interface/IInterface.h\"\n\nnamespace hpe\n{\n    template <typename D"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/DataObject/CloudXYZRGBA.h",
    "chars": 666,
    "preview": "#pragma once\n\n#ifndef CLOUDXYZRGBA_H\n#define CLOUDXYZRGBA_H\n\n#include <DataObject/IDataObject.h>\n\n#include <pcl/point_ty"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/DataObject/HeadPoseInfo.h",
    "chars": 828,
    "preview": "#ifndef HEADPOSEINFO_H\n#define HEADPOSEINFO_H\n\n#include <DataObject/IDataObject.h>\n\nnamespace hpe\n{\n    class HeadPoseIn"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/DataObject/IDataObject.h",
    "chars": 456,
    "preview": "#pragma once\n\n#ifndef IDATAOBJECT_H\n#define IDATAOBJECT_H\n\n#include <Interface/IInterface.h>\n\n#include <memory>\n\nnamespa"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/DataObject/IDataStorage.h",
    "chars": 1761,
    "preview": "#pragma once\n\n#ifndef IDATASTORAGE_H\n#define IDATASTORAGE_H\n\n#include <Interface/IInterface.h>\n#include <DataObject/IDat"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/DataObject/LandmarksObject.h",
    "chars": 380,
    "preview": "#pragma once\n\n#ifndef LANDMARKSOBJECT_H\n#define LANDMARKSOBJECT_H\n\n#include <DataObject/IDataObject.h>\n\n#include <Landma"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/DataObject/MapDataStorage.cpp",
    "chars": 454,
    "preview": "#include \"MapDataStorage.h\"\n\nnamespace hpe\n{\n    void MapDataStorage::Set(std::string key, IDataObject::Ptr object)\n    "
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/DataObject/MapDataStorage.h",
    "chars": 458,
    "preview": "#pragma once\n\n#ifndef MAPDATASTORAGE_H\n#define MAPDATASTORAGE_H\n\n#include <DataObject/IDataStorage.h>\n#include <map>\n\nna"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/DataObject/RawFrames.h",
    "chars": 335,
    "preview": "#pragma once\n\n#ifndef RAWFRAMES_H\n#define RAWFRAMES_H\n\n#include <DataObject/IDataObject.h>\n\n#include <opencv2/opencv.hpp"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/DepthDetector.cpp",
    "chars": 1418,
    "preview": "#include \"DepthDetector.h\"\n\n#include <boost/math/special_functions/fpclassify.hpp>\n\nnamespace hpe\n{\n\n    DepthDetector::"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/DepthDetector.h",
    "chars": 500,
    "preview": "#pragma once\n\n#ifndef DEPTHDETECTOR_H\n#define DEPTHDETECTOR_H\n\n#include <opencv2/opencv.hpp>\n\n#include \"localFunctions.h"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/LeafNode.cpp",
    "chars": 3278,
    "preview": "#include <cmath>\n#include <algorithm>\n#include <vector>\n#include <iostream>\n#include <opencv2/highgui/highgui.hpp>\n#incl"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/LeafNode.h",
    "chars": 797,
    "preview": "#ifndef LEAFNODE_H\n#define LEAFNODE_H\n\n#include <opencv2/highgui/highgui.hpp>\n#include <opencv2/imgproc/imgproc.hpp>\nusi"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/Tree.cpp",
    "chars": 1305,
    "preview": "#include <cmath>\n#include <algorithm>\n#include <vector>\n#include <iostream>\n#include <opencv2/highgui/highgui.hpp>\n#incl"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/Tree.h",
    "chars": 367,
    "preview": "#pragma once\n#ifndef TREE_H\n#define TREE_H\n\n#include <opencv2/highgui/highgui.hpp>\n#include <opencv2/imgproc/imgproc.hpp"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/csvMat.cpp",
    "chars": 1043,
    "preview": "#include <cmath>\n#include <algorithm>\n#include <vector>\n#include <iostream>\n#include <opencv2/highgui/highgui.hpp>\n#incl"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/csvMat.h",
    "chars": 307,
    "preview": "#pragma once\n#ifndef CSVMAT_H\n#define CSVMAT_H\n\n#include <string>\n#include <algorithm>\n#include <iostream>\n#include <vec"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/localFunctions.cpp",
    "chars": 18483,
    "preview": "#include <string>\n#include <algorithm>\n#include <iostream>\n#include <vector>\n#include <stdint.h>\n#include <opencv2/openc"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Detector/DepthFrameDetector/localFunctions.h",
    "chars": 973,
    "preview": "#ifndef LOCALFUNCTIONS_H\n#define LOCALFUNCTIONS_H\n\n#include <string>\n#include <algorithm>\n#include <iostream>\n#include <"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Exception/HPEException.cpp",
    "chars": 173,
    "preview": "#include \"HPEException.h\"\n\nHPEException::HPEException(std::string message)\n    : m_message(message)\n{\n\n}\n\nconst char *HP"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Exception/HPEException.h",
    "chars": 279,
    "preview": "#ifndef HPEEXCEPTION_H\n#define HPEEXCEPTION_H\n\n#include <stdexcept>\n\nclass HPEException : public std::exception\n{\n    pu"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/FacialExpressions/ferLocalFunctions.cpp",
    "chars": 27849,
    "preview": "#include <string>\n#include <algorithm>\n#include <iostream>\n#include <vector>\n#include <stdint.h>\n#include \"opencv2/core/"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/FacialExpressions/ferLocalFunctions.h",
    "chars": 1844,
    "preview": "#ifndef FERLOCALFUNCTIONS_H\n#define FERLOCALFUNCTIONS_H\n\n#include <string>\n#include <algorithm>\n#include <iostream>\n#inc"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/CylinderOptimizedFeatureCalculator.cpp",
    "chars": 69,
    "preview": "//#include \"CylinderOptimizedFeatureCalculator.h\"\n\nnamespace hpe\n{\n\n}"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/CylinderOptimizedFeatureCalculator.h",
    "chars": 11635,
    "preview": "#pragma once\n\n#ifndef CYLINDEROPTIMIZEDFEATURECALCULATOR_H\n#define CYLINDEROPTIMIZEDFEATURECALCULATOR_H\n\n#include <Featu"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/FeatureCalculatorBase.h",
    "chars": 3985,
    "preview": "#pragma once\n\n#ifndef FEATURE_CALCULATOR_BASE_H\n#define FEATURE_CALCULATOR_BASE_H\n\n#include <pcl/point_types.h>\n#include"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Features/Calculator/IFeatureCalculator.h",
    "chars": 369,
    "preview": "#pragma once\n\n#ifndef I_FEATURE_CALCULATOR_H\n#define I_FEATURE_CALCULATOR_H\n\n#include \"Interface/IInterface.h\"\n\nnamespac"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Features/IFeature.h",
    "chars": 526,
    "preview": "#pragma once\n\n#ifndef I_FEATURE_H\n#define I_FEATURE_H\n\n#include <pcl/point_cloud.h>\n#include <opencv2/opencv.hpp>\n\n#incl"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Features/Sampler/CylinderSampler.cpp",
    "chars": 10221,
    "preview": "#define _CRT_SECURE_NO_WARNINGS\n\n#include <opencv2\\opencv.hpp>\n\n#include \"CylinderSampler.h\"\n\n#include <Exception/HPEExc"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Features/Sampler/CylinderSampler.h",
    "chars": 1942,
    "preview": "#pragma once\n\n#include <Features/Sampler/IPatchSampler.h>\n\n#include <pcl/ModelCoefficients.h>\n\n#ifndef CYLINDERSAMPLER_H"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Features/Sampler/IPatchSampler.h",
    "chars": 1301,
    "preview": "#pragma once\n#pragma once\n\n#ifndef I_PATCH_SAMPLER\n#define I_PATCH_SAMPLER\n\n#include <pcl/point_cloud.h>\n#include <pcl/M"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Filter/BoxFilter.h",
    "chars": 1545,
    "preview": "#ifndef BOXFILTER_H\n#define BOXFILTER_H\n\n#include \"Filter/ICloudFilter.h\"\n#include \"Filter/Filters.h\"\n\nnamespace hpe\n{\n "
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Filter/CenteredBoxFilter.h",
    "chars": 1347,
    "preview": "#ifndef CENTEREDBOXFILTER_H\n#define CENTEREDBOXFILTER_H\n\n#include \"Filter/ICenterCloudFilter.h\"\n#include \"Filter/Filters"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Filter/FilteringQueue.h",
    "chars": 1793,
    "preview": "#pragma once\n\n#ifndef FILTERINGQUEUE_H\n#define FILTERINGQUEUE_H\n\n#include <pcl/point_cloud.h>\n#include <pcl/common/commo"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Filter/Filters.h",
    "chars": 4194,
    "preview": "#ifndef FILTERS_H\n#define FILTERS_H\n\n#include <pcl/point_cloud.h>\n\n#include <pcl/filters/voxel_grid.h>\n#include <pcl/fil"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Filter/FunctorFilter.h",
    "chars": 1111,
    "preview": "#ifndef FUNCTORFILTER_H\n#define FUNCTORFILTER_H\n\n#include <functional>\n\n#include <pcl/point_cloud.h>\n#include \"Filter/IC"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Filter/ICenterCloudFilter.h",
    "chars": 475,
    "preview": "#ifndef ICENTERCLOUDFILTER_H\n#define ICENTERCLOUDFILTER_H\n\n#include <Interface/IInterface.h>\n#include <pcl/point_types.h"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Filter/ICloudFilter.h",
    "chars": 648,
    "preview": "#ifndef ICLOUDFILTER_H\n#define ICLOUDFILTER_H\n\n#include <Interface/IInterface.h>\n#include <pcl/point_types.h>\n#include <"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Filter/MovingLeastSquaresFilter.h",
    "chars": 1241,
    "preview": "#pragma once\n\n#ifndef MOVINGLEASTSQUARESFILTER_H\n#define MOVINGLEASTSQUARESFILTER_H\n\n#include <Filter/ICloudFilter.h>\n\n#"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Grabber/GrabberBase.cpp",
    "chars": 1672,
    "preview": "#include \"GrabberBase.h\"\n\n#include <DataObject/RawFrames.h>\n#include <pcl/common/time.h>\n\nnamespace hpe\n{\n\n    GrabberBa"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Grabber/GrabberBase.h",
    "chars": 1504,
    "preview": "#pragma once\n\n#ifndef GRABBERBASE_H\n#define GRABBERBASE_H\n\n#include <opencv2/opencv.hpp>\n\n#include <DataObject/IDataObje"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Grabber/OpenNIGrabber.cpp",
    "chars": 2282,
    "preview": "#include \"OpenNIGrabber.h\"\n\n#include <DataObject/MapDataStorage.h>\n\nnamespace hpe\n{\n\n    OpenNIGrabber::OpenNIGrabber(vo"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Grabber/OpenNIGrabber.h",
    "chars": 1117,
    "preview": "#pragma once\n#ifndef OPENNIGRABBER_H\n#define OPENNIGRABBER_H\n\n#include <Grabber/GrabberBase.h>\n\n#include <pcl/io/openni_"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Grabber/PCDGrabber.cpp",
    "chars": 2791,
    "preview": "#include \"PCDGrabber.h\"\n\n#include <DataObject/MapDataStorage.h>\n#include <DataObject/CloudXYZRGBA.h>\n#include <boost/for"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Grabber/PCDGrabber.h",
    "chars": 871,
    "preview": "#pragma once\n\n#include <Grabber/GrabberBase.h>\n#include <DataObject/IDataObject.h>\n\nclass PCDGrabber : public hpe::Grabb"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Grabber/ProviderGrabber.cpp",
    "chars": 1096,
    "preview": "#include \"ProviderGrabber.h\"\n\n#include <Exception/HPEException.h>\n#include <DataObject/MapDataStorage.h>\n\nnamespace hpe\n"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Grabber/ProviderGrabber.h",
    "chars": 982,
    "preview": "#pragma once\n\n#ifndef PROVIDERGRABBER_H\n#define PROVIDERGRABBER_H\n\n#include <Grabber/GrabberBase.h>\n#include <Provider/I"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/HeadPoseEstimationFramework.vcxproj",
    "chars": 14644,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microso"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Helpers/HpeHelpers.cpp",
    "chars": 1383,
    "preview": "#include \"HpeHelpers.h\"\n\n\n\nnamespace hpe\n{\n    Eigen::Vector3f VectorToEulerAngles(Eigen::Vector3f v)\n    {\n        Eige"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Helpers/HpeHelpers.h",
    "chars": 1187,
    "preview": "#pragma once\n\n#ifndef HPEHELPERS_H\n#define HPEHELPERS_H\n\n#include <pcl/common/common.h>\n#include <pcl/point_cloud.h>\n#in"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Interface/IInterface.h",
    "chars": 186,
    "preview": "#pragma once\n\n#ifndef IINTERFACE_H\n#define IINTERFACE_H\n\nnamespace hpe\n{\n    class IInterface\n    {\n        public:\n    "
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Landmarks.h",
    "chars": 4510,
    "preview": "#ifndef LANDMARKS_H\n#define LANDMARKS_H\n\n#include <fstream>\n#include <ostream>\n#include <istream>\n#include <string>\n#inc"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/ConverterProcessor.cpp",
    "chars": 1623,
    "preview": "#include \"ConverterProcessor.h\"\n#include <Exception/HPEException.h>\n#include <DataObject/RawFrames.h>\n#include <DataObje"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/ConverterProcessor.h",
    "chars": 1308,
    "preview": "#pragma once\n\n#ifndef CONVERTERPROCESSOR_H\n#define CONVERTERPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n#include <Con"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/DepthPreprocessingProcessor.cpp",
    "chars": 3161,
    "preview": "#include \"DepthPreprocessingProcessor.h\"\n#include <DataObject/RawFrames.h>\n#include <DataObject/CloudXYZRGBA.h>\n#include"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/DepthPreprocessingProcessor.h",
    "chars": 1289,
    "preview": "#pragma once\n\n#ifndef DEPTHPREPROCESSINGPROCESSOR_H\n#define DEPTHPREPROCESSINGPROCESSOR_H\n\n#include <Processor/IProcesso"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/DetectorProcessor.cpp",
    "chars": 1680,
    "preview": "#include \"DetectorProcessor.h\"\n\n#include <DataObject/RawFrames.h>\n#include <DataObject/HeadPoseInfo.h>\n\n#include <Conver"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/DetectorProcessor.h",
    "chars": 522,
    "preview": "#pragma once\n\n#ifndef DETECTORPROCESSOR_H\n#define DETECTORPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n#include <Detec"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/FacialExpressionsProcessor.cpp",
    "chars": 6676,
    "preview": "#include \"FacialExpressionsProcessor.h\"\n\n#include <DataObject/CloudXYZRGBA.h>\n#include <DataObject/LandmarksObject.h>\n\n#"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/FacialExpressionsProcessor.h",
    "chars": 1721,
    "preview": "#pragma once\n\n#ifndef FACIALEXPRESSIONSPROCESSOR_H\n#define FACIALEXPRESSIONSPROCESSOR_H\n\n#include <Processor/IProcessor."
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/FilterProcessor.cpp",
    "chars": 696,
    "preview": "\n#include <Processor/FilterProcessor.h>\n#include <DataObject/CloudXYZRGBA.h>\n#include <DataObject/IDataStorage.h>\n\nnames"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/FilterProcessor.h",
    "chars": 591,
    "preview": "#pragma once\n\n#ifndef FILTERPROCESSOR_H\n#define FILTERPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n#include <Filter/IC"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/HeadExtractionProcessor.cpp",
    "chars": 2972,
    "preview": "#include \"HeadExtractionProcessor.h\"\n\n#include <UI/PointPicker.h>\n\n#include <DataObject/CloudXYZRGBA.h>\n#include <DataOb"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/HeadExtractionProcessor.h",
    "chars": 783,
    "preview": "#pragma once\n\n#ifndef HEADEXTRACTIONPROCESSOR_H\n#define HEADEXTRACTIONPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n//#"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/IProcessor.h",
    "chars": 440,
    "preview": "#pragma once\n\n#ifndef IPROCESSOR_H\n#define IPROCESSOR_H\n\n#include <Interface/IInterface.h>\n#include <DataObject/IDataSto"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/SaveCloudProcessor.cpp",
    "chars": 3244,
    "preview": "#include \"SaveCloudProcessor.h\"\n\n#include <pcl/io/pcd_io.h>\n#include <pcl/filters/conditional_removal.h>\n#include <boost"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/SaveCloudProcessor.h",
    "chars": 1181,
    "preview": "#pragma once\n\n#ifndef SAVECLOUDPROCESSOR_H\n#define SAVECLOUDPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n#include <ope"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/ShowCloudProcessor.cpp",
    "chars": 1447,
    "preview": "#include \"ShowCloudProcessor.h\"\n\n#include <DataObject/CloudXYZRGBA.h>\n#include <pcl/common/time.h>\n\nnamespace hpe\n{\n\n   "
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/ShowCloudProcessor.h",
    "chars": 835,
    "preview": "#pragma once\n\n#ifndef SHOWCLOUDPROCESSOR_H\n#define SHOWCLOUDPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n#include <pcl"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/TemplateCreatorProcessor.cpp",
    "chars": 977,
    "preview": "#include \"TemplateCreatorProcessor.h\"\n\n#include <DataObject/CloudXYZRGBA.h>\n\nnamespace hpe\n{\n\n    TemplateCreatorProcess"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/TemplateCreatorProcessor.h",
    "chars": 988,
    "preview": "#pragma once\n\n#ifndef TEMPLATECREATORPROCESSOR_H\n#define TEMPLATECREATORPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n#"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/TrackingProcessor.cpp",
    "chars": 8460,
    "preview": "#include \"TrackingProcessor.h\"\n\n#include <pcl/common/common.h>\n#include <pcl/io/io.h>\n#include <pcl/search/kdtree.h>\n\n#i"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Processor/TrackingProcessor.h",
    "chars": 1989,
    "preview": "#pragma once\n\n#ifndef TRACKINGPROCESSOR_H\n#define TRACKINGPROCESSOR_H\n\n#include <pcl/point_types.h>\n#include <pcl/point_"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Provider/IDataProvider.h",
    "chars": 963,
    "preview": "#ifndef IDATAPROVIDER_H\n#define IDATAPROVIDER_H\n\n#include <Interface/IInterface.h>\n#include <Common.h>\n\n#include <opencv"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Provider/RawDataProvider.cpp",
    "chars": 4892,
    "preview": "#include \"RawDataProvider.h\"\n\n#include <Provider/CvMatRawSerializer.h>\n#include <Converter/KinectDataConverter.h>\n#inclu"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Provider/RawDataProvider.h",
    "chars": 1255,
    "preview": "#ifndef RAWDATAPROVIDER_H\n#define RAWDATAPROVIDER_H\n\n#include <vector>\n#include <pcl/point_types.h>\n#include <pcl/point_"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Settings/HPESettings.cpp",
    "chars": 1808,
    "preview": "#include \"HPESettings.h\"\n\n#include <Exception/HPEException.h>\n\n#include <boost/property_tree/ini_parser.hpp>\n#include <b"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Settings/HPESettings.h",
    "chars": 2738,
    "preview": "#pragma once\n\n#ifndef HPESETTINGS_H\n#define HPESETTINGS_H\n\n#include <boost/property_tree/ptree.hpp>\n#include <boost/lexi"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/Tracker/ICPTemplateTracker.h",
    "chars": 7138,
    "preview": "#ifndef ICPTEMPLATETRACKER_H\n#define ICPTEMPLATETRACKER_H\n\n#include \"Common.h\"\n#include \"Align/CloudMapper.h\"\n#include <"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/UI/PointPicker.h",
    "chars": 10151,
    "preview": "#pragma once\n\n#ifndef POINTPICKER_H\n#define POINTPICKER_H\n\n#include <vector>\n\n#include <pcl/point_types.h>\n#include <pcl"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/UI/ShowCloud.h",
    "chars": 8051,
    "preview": "#ifndef SHOWCLOUD_H\n#define SHOWCLOUD_H\n\n#include <pcl/point_types.h>\n#include <pcl/point_cloud.h>\n#include <pcl/common/"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/UI/ShowMesh.h",
    "chars": 685,
    "preview": "#pragma once\n\n#ifndef SHOWMESH_H\n#define SHOWMESH_H\n\n#include <pcl/visualization/pcl_visualizer.h>\n#include <pcl/Polygon"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/UI/VisualizerCommon.h",
    "chars": 1262,
    "preview": "#ifndef VISUALIZERCOMMON_H\n#define VISUALIZERCOMMON_H\n\n#include <vtkPolyDataMapper.h>\n#include <vtkActor.h>\n#include <vt"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/WindowsOnly/Grabber/KinectSDKGrabber.cpp",
    "chars": 8616,
    "preview": "#include \"KinectSDKGrabber.h\"\n\n#include <DataObject/MapDataStorage.h>\n#include <Exception/HPEException.h>\n\n#include <pcl"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/WindowsOnly/Grabber/KinectSDKGrabber.h",
    "chars": 1446,
    "preview": "#pragma once\n\n#ifndef KINECTSDKGRABBER_H\n#define KINECTSDKGRABBER_H\n\n#include <Grabber/GrabberBase.h>\n#include <DataObje"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/WindowsOnly/Processor/KinectSDKConverterProcessor.cpp",
    "chars": 4707,
    "preview": "#include \"KinectSDKConverterProcessor.h\"\n\n#include <boost/math/special_functions/fpclassify.hpp>\n#include <boost/math/sp"
  },
  {
    "path": "FaceCept3D/HeadPoseEstimationFramework/WindowsOnly/Processor/KinectSDKConverterProcessor.h",
    "chars": 862,
    "preview": "#ifndef KINECTSDKCONVERTERPROCESSOR_H\n#define KINECTSDKCONVERTERPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n\n#include"
  },
  {
    "path": "FaceCept3D/TemplateCreator/CMakeLists.txt",
    "chars": 636,
    "preview": "cmake_minimum_required(VERSION 2.8)\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++11\")\n\nset(HEAD_POSE_ESTIMATION \"Hea"
  },
  {
    "path": "FaceCept3D/TemplateCreator/TemplateCreator.cpp",
    "chars": 2460,
    "preview": "// TemplateCreator.cpp : Defines the entry point for the console application.\n//\n\n#include \"stdafx.h\"\n\n#include <Filter/"
  },
  {
    "path": "FaceCept3D/TemplateCreator/TemplateCreator.vcxproj",
    "chars": 8047,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microso"
  },
  {
    "path": "FaceCept3D/TemplateCreator/UIProcessor.cpp",
    "chars": 935,
    "preview": "#include \"stdafx.h\"\n#include \"UIProcessor.h\"\n\nUIProcessor::UIProcessor(void)\n    : m_grabber(nullptr), m_templateCreatio"
  },
  {
    "path": "FaceCept3D/TemplateCreator/UIProcessor.h",
    "chars": 934,
    "preview": "#pragma once\n\n#ifndef UIPROCESSOR_H\n#define UIPROCESSOR_H\n\n#include <Processor/ShowCloudProcessor.h>\n#include <Processor"
  },
  {
    "path": "FaceCept3D/TemplateCreator/settings.ini",
    "chars": 59,
    "preview": "Template=MyTemplate.pcd\nLandmarks=MyTemplateLandmarks.txt\n\n"
  },
  {
    "path": "FaceCept3D/TemplateCreator/stdafx.cpp",
    "chars": 294,
    "preview": "// stdafx.cpp : source file that includes just the standard includes\n// TemplateCreator.pch will be the pre-compiled hea"
  },
  {
    "path": "FaceCept3D/TemplateCreator/stdafx.h",
    "chars": 912,
    "preview": "// stdafx.h : include file for standard system include files,\n// or project specific include files that are used frequen"
  },
  {
    "path": "FaceCept3D/TemplateTracker/ShowTwoCloudsProcessor.cpp",
    "chars": 1783,
    "preview": "#include \"stdafx.h\"\n#include \"ShowTwoCloudsProcessor.h\"\n\n#include <DataObject/CloudXYZRGBA.h>\n#include <Grabber/PCDGrabb"
  },
  {
    "path": "FaceCept3D/TemplateTracker/ShowTwoCloudsProcessor.h",
    "chars": 623,
    "preview": "#pragma once\n\n#ifndef SHOWTWOCLOUDSPROCESSOR_H\n#define SHOWTWOCLOUDSPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n#incl"
  },
  {
    "path": "FaceCept3D/TemplateTracker/TemplateTracker.cpp",
    "chars": 2848,
    "preview": "// TemplateTracker.cpp : Defines the entry point for the console application.\n//\n\n#include \"stdafx.h\"\n\n#include \"ShowTwo"
  },
  {
    "path": "FaceCept3D/TemplateTracker/TemplateTracker.vcxproj",
    "chars": 11735,
    "preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microso"
  },
  {
    "path": "FaceCept3D/TemplateTracker/UIProcessor.cpp",
    "chars": 1138,
    "preview": "#include \"stdafx.h\"\n#include \"UIProcessor.h\"\n\n#include <DataObject/RawFrames.h>\n#include <opencv2/opencv.hpp>\n\nUIProcess"
  },
  {
    "path": "FaceCept3D/TemplateTracker/UIProcessor.h",
    "chars": 827,
    "preview": "#pragma once\n\n#ifndef UIPROCESSOR_H\n#define UIPROCESSOR_H\n\n#include <Processor/TemplateCreatorProcessor.h>\n#include <Gra"
  },
  {
    "path": "FaceCept3D/TemplateTracker/VisuilizeProcessor.cpp",
    "chars": 9192,
    "preview": "#include \"stdafx.h\"\n#include \"VisuilizeProcessor.h\"\n\n#include <DataObject/LandmarksObject.h>\n#include <DataObject/CloudX"
  },
  {
    "path": "FaceCept3D/TemplateTracker/VisuilizeProcessor.h",
    "chars": 1428,
    "preview": "#pragma once\n\n#ifndef VISUALIZEPROCESSOR_H\n#define VISUALIZEPROCESSOR_H\n\n#include <Processor/IProcessor.h>\n#include <Pro"
  },
  {
    "path": "FaceCept3D/TemplateTracker/VoxelizeProcessor.cpp",
    "chars": 655,
    "preview": "#include \"stdafx.h\"\n#include \"VoxelizeProcessor.h\"\n\n#include <Filter/Filters.h>\n#include <DataObject/CloudXYZRGBA.h>\n\nVo"
  },
  {
    "path": "FaceCept3D/TemplateTracker/VoxelizeProcessor.h",
    "chars": 292,
    "preview": "#pragma once\n\n#include <Processor/IProcessor.h>\n\nclass VoxelizeProcessor : public hpe::IProcessor\n{\n    public:\n        "
  },
  {
    "path": "FaceCept3D/TemplateTracker/settings.ini",
    "chars": 361,
    "preview": "DistanceToShow=1.2\nStoreFolder=d:\\Documents\\Image Databases\\video\n\nDetectorData=d:\\Projects\\HeadPoseEstimation\\Data\\Dete"
  },
  {
    "path": "FaceCept3D/TemplateTracker/stdafx.cpp",
    "chars": 294,
    "preview": "// stdafx.cpp : source file that includes just the standard includes\n// TemplateTracker.pch will be the pre-compiled hea"
  },
  {
    "path": "FaceCept3D/TemplateTracker/stdafx.h",
    "chars": 739,
    "preview": "// stdafx.h : include file for standard system include files,\n// or project specific include files that are used frequen"
  },
  {
    "path": "LICENSE",
    "chars": 1104,
    "preview": "The MIT License (MIT)\r\n\r\nCopyright (c) 2015 sergeytulyakov\r\n\r\nPermission is hereby granted, free of charge, to any perso"
  },
  {
    "path": "README.md",
    "chars": 6408,
    "preview": "# FaceCept3D\r\nFaceCept3D: 3D Face Analysis and Recognition\r\n\r\n## Introduction\r\n\r\nFaceCept3D is a realtime framework for "
  }
]

About this extraction

This page contains the full source code of the sergeytulyakov/FaceCept3D GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 128 files (331.9 KB), approximately 88.2k tokens, and a symbol index with 139 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!