Changeset 1251 for GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
- Timestamp:
- 08/21/06 18:39:49 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1233 r1251 16 16 #include "OspTree.h" 17 17 #include "ObjParser.h" 18 #ifdef INTEL_COMPILER18 #ifdef GTP_INTERNAL 19 19 #include "ArchModeler2MLRT.hxx" 20 20 #endif … … 123 123 mVspBspTree(NULL), 124 124 mViewCellsManager(NULL), 125 mRenderSimulator(NULL) 125 mRenderSimulator(NULL), 126 mPass(0) 126 127 { 127 128 Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer); … … 757 758 { 758 759 case INTEL_RAYCASTER: 759 #ifdef INTEL_COMPILER760 #ifdef GTP_INTERNAL 760 761 return mlrtaLoadAS(externKdTree.c_str()); 761 762 #endif … … 768 769 } 769 770 770 } 771 772 int Preprocessor::CastIntelDoubleRay( 773 const Vector3 &viewPoint, 774 const Vector3 &direction, 775 const float probability, 776 VssRayContainer &vssRays, 777 const AxisAlignedBox3 &box 778 ) 779 { 780 VssRay *vssRay = NULL; 781 int hits = 0; 782 783 Vector3 pointA, pointB; 784 785 Intersectable *objectA = 786 CastIntelSingleRay(viewPoint, direction, pointA, box); 787 788 // cast ray into other direction 789 Intersectable *objectB = 790 CastIntelSingleRay(viewPoint, -direction, pointB, box); 791 792 const bool validSample = (objectA != objectB); 793 794 if (validSample) 795 { 796 if (objectA) 797 { 798 vssRay = new VssRay(pointB, 799 pointA, 800 objectB, 801 objectA, 802 probability, 803 mPass); 804 805 vssRays.push_back(vssRay); 806 hits ++; 807 } 808 809 if (objectB) 810 { 811 vssRay = new VssRay(pointA, 812 pointB, 813 objectA, 814 objectB, 815 probability, 816 mPass); 817 818 vssRays.push_back(vssRay); 819 hits ++; 820 } 821 //Debug << "intel ray: " << *vssRay << endl; 822 } 823 //cout << "a"; 824 return hits; 825 } 826 827 828 Intersectable *Preprocessor::CastIntelSingleRay(const Vector3 &viewPoint, 829 const Vector3 &direction, 830 //const float probability, 831 Vector3 &tPoint, 832 const AxisAlignedBox3 &box 833 ) 834 { 835 AxisAlignedBox3 sbox = box; 836 sbox.Enlarge(Vector3(-Limits::Small)); 837 838 if (!sbox.IsInside(viewPoint)) 839 return 0; 840 841 float pforg[3]; 842 float pfdir[3]; 843 double pfnorm[3]; 844 845 pforg[0] = viewPoint[0]; pforg[1] = viewPoint[1]; pforg[2] = viewPoint[2]; 846 pfdir[0] = direction[0]; pfdir[1] = direction[1]; pfdir[2] = direction[2]; 847 848 float dist = 0; 849 #ifdef GTP_INTERNAL 850 const int hittriangle = mlrtaIntersectAS(pforg, pfdir, pfnorm, dist); 851 #else 852 const int hittriangle = -1; 853 #endif 854 855 if (hittriangle == -1) 856 { 857 static Ray ray; 858 SetupRay(ray, viewPoint, direction); 859 860 float tmin = 0, tmax; 861 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 862 { 863 tPoint = ray.Extrap(tmax); 864 } 865 866 return NULL; 867 } 868 else 869 { 870 tPoint[0] = pforg[0] + pfdir[0] * dist; 871 tPoint[1] = pforg[1] + pfdir[1] * dist; 872 tPoint[2] = pforg[2] + pfdir[2] * dist; 873 874 return mFaceParents[hittriangle]; 875 } 876 } 877 878 879 int Preprocessor::CastInternalRay( 880 const Vector3 &viewPoint, 881 const Vector3 &direction, 882 const float probability, 883 VssRayContainer &vssRays, 884 const AxisAlignedBox3 &box 885 ) 886 { 887 int hits = 0; 888 static Ray ray; 889 890 AxisAlignedBox3 sbox = box; 891 sbox.Enlarge(Vector3(-Limits::Small)); 892 893 if (!sbox.IsInside(viewPoint)) 894 return 0; 895 896 SetupRay(ray, viewPoint, direction); 897 898 // cast ray to KD tree to find intersection with other objects 899 Intersectable *objectA, *objectB; 900 901 Vector3 pointA; 902 Vector3 pointB; 903 904 //float bsize = Magnitude(box.Size()); 905 if (!mDetectEmptyViewSpace) 906 ray.mFlags &= ~Ray::CULL_BACKFACES; 907 else 908 ray.mFlags |= Ray::CULL_BACKFACES; 909 910 if (mKdTree->CastRay(ray)) 911 { 912 objectA = ray.intersections[0].mObject; 913 pointA = ray.Extrap(ray.intersections[0].mT); 914 } 915 else 916 { 917 objectA = NULL; 918 // compute intersection with the scene bounding box 919 float tmin, tmax; 920 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 921 pointA = ray.Extrap(tmax); 922 else 923 return 0; 924 } 925 926 // matt: point A could be undefined? 927 928 // cast ray into opposite direction 929 if (1 && mDetectEmptyViewSpace) { 930 SetupRay(ray, pointA, -direction); 931 } else 932 SetupRay(ray, viewPoint, -direction); 933 934 if (!mDetectEmptyViewSpace) 935 ray.mFlags &= ~Ray::CULL_BACKFACES; 936 else 937 ray.mFlags |= Ray::CULL_BACKFACES; 938 939 if (mKdTree->CastRay(ray)) 940 { 941 objectB = ray.intersections[0].mObject; 942 pointB = ray.Extrap(ray.intersections[0].mT); 943 } 944 else 945 { 946 objectB = NULL; 947 float tmin, tmax; 948 949 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 950 pointB = ray.Extrap(tmax); 951 else 952 return 0; 953 } 954 955 //bool thesame = objectA && (objectA == objectB); 956 957 // if (objectA == NULL && objectB != NULL) { 958 if (1 && mDetectEmptyViewSpace) 959 { 960 // cast again to ensure that there is no objectA 961 SetupRay(ray, pointB, direction); 962 ray.mFlags |= Ray::CULL_BACKFACES; 963 964 if (mKdTree->CastRay(ray)) 965 { 966 objectA = ray.intersections[0].mObject; 967 pointA = ray.Extrap(ray.intersections[0].mT); 968 } 969 } 970 971 972 VssRay *vssRay = NULL; 973 974 bool validSample = (objectA != objectB); 975 976 //if (validSample && thesame) Debug << "warning!!" << endl; 977 978 if (0 && mDetectEmptyViewSpace) 979 { 980 // consider all samples valid 981 // check if the viewpoint lies on the line segment AB 982 if (Distance(pointA, pointB) < 983 Distance(viewPoint, pointA) + Distance(viewPoint, pointB) - Limits::Small) 984 { 985 validSample = false; 986 } 987 } 988 989 if (validSample) 990 { 991 if (objectA) 992 { 993 vssRay = new VssRay(pointB, 994 pointA, 995 objectB, 996 objectA, 997 probability, 998 mPass); 999 vssRays.push_back(vssRay); 1000 hits ++; 1001 } 1002 1003 if (objectB) 1004 { 1005 vssRay = new VssRay(pointA, 1006 pointB, 1007 objectA, 1008 objectB, 1009 probability, 1010 mPass); 1011 vssRays.push_back(vssRay); 1012 hits ++; 1013 } 1014 //Debug << "internal ray: " << *vssRay << endl << endl; 1015 } 1016 //cout << "b"; 1017 return hits; 1018 } 1019 1020 1021 int Preprocessor::CastRay( 1022 const Vector3 &viewPoint, 1023 const Vector3 &direction, 1024 const float probability, 1025 VssRayContainer &vssRays, 1026 const AxisAlignedBox3 &box 1027 ) 1028 { 1029 switch (mRayCastMethod) 1030 { 1031 case INTEL_RAYCASTER: 1032 return CastIntelDoubleRay(viewPoint, direction, probability, vssRays, box); 1033 case INTERNAL_RAYCASTER: 1034 default: 1035 return CastInternalRay(viewPoint, direction, probability, vssRays, box); 1036 } 1037 } 1038 1039 1040 void Preprocessor::SetupRay(Ray &ray, 1041 const Vector3 &point, 1042 const Vector3 &direction 1043 ) 1044 { 1045 ray.Clear(); 1046 // do not store anything else then intersections at the ray 1047 ray.Init(point, direction, Ray::LOCAL_RAY); 1048 } 1049 1050 }
Note: See TracChangeset
for help on using the changeset viewer.