NoobsDeSroobs

Unresolved external symbol, where AAAAARE you?

Jan 14th, 2015
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.45 KB | None | 0 0
  1. //HEADER
  2.  
  3. // Fill out your copyright notice in the Description page of Project Settings.
  4.  
  5. #pragma once
  6.  
  7. #include <string>
  8.  
  9. /**
  10.  *
  11.  */
  12. class LearnUnreal_API PointcloudSmoothener
  13. {
  14. public:
  15.     PointcloudSmoothener(TCHAR* path);
  16.     ~PointcloudSmoothener();
  17.  
  18.     //Make public for testing
  19.     TArray<FVector> Points;
  20.  
  21.     TArray<FVector> smoothByAvarage(TArray<FVector> points);
  22.  
  23.  
  24. private:
  25.     TArray<FVector> constructPointVectors(TArray<FString> data);
  26.  
  27. };
  28.  
  29.  
  30. //Source File
  31.  
  32. // Fill out your copyright notice in the Description page of Project Settings.
  33.  
  34. #include "LearnUnrealTest.h"
  35. #include "PointcloudSmoothener.h"
  36. #include <stdlib.h>
  37.  
  38. //Read the file contents and construct the meshPoints
  39. PointcloudSmoothener::PointcloudSmoothener(TCHAR* path)
  40. {
  41.     TArray<FString> Lines;
  42.     bool ReadSuccess = FFileHelper::LoadANSITextFileToStrings(path, NULL, Lines);
  43.     if (ReadSuccess) {
  44.         Points = constructPointVectors(Lines);
  45.         Points = smoothByAvarage(Points);
  46.     }
  47. }
  48.  
  49. PointcloudSmoothener::~PointcloudSmoothener()
  50. {
  51. }
  52.  
  53. //Smooth out the pointcloud removing unnecessary points
  54. TArray<FVector> smoothByAvarage(TArray<FVector> points)
  55. {
  56.     TArray<FVector> pointList;
  57.     pointList.Reserve(points.Num() - 2);
  58.  
  59.     for (int i = 2; i < points.Num(); i++) {
  60.         pointList[i - 2] = points[i];
  61.     }
  62.  
  63.     size_t distance = 4;
  64.     size_t end = pointList.Num() - distance;
  65.     FVector basePlaneDirection = (pointList[distance] - pointList[0]);
  66.     basePlaneDirection.Normalize();
  67.     FVector newPlaneDirection;
  68.     TArray<FVector> smoothPointCloud;
  69.     smoothPointCloud.Reserve(2);
  70.  
  71.     smoothPointCloud[0] = points[0];
  72.     smoothPointCloud[1] = points[1];
  73.  
  74.  
  75.     smoothPointCloud.Add(pointList[0]);
  76.     for (size_t i = 1; i < end; i++) {
  77.         newPlaneDirection = pointList[(i + distance) % (pointList.Num())] - pointList[i];
  78.  
  79.         FVector NormalizedBaseVector = basePlaneDirection;
  80.         NormalizedBaseVector.Normalize();
  81.         FVector NormalizedNewvector = newPlaneDirection;
  82.         NormalizedNewvector.Normalize();
  83.  
  84.         //If a sharp turn/angle
  85.         if (FVector::DotProduct(NormalizedBaseVector, NormalizedNewvector) < 0.7f) {
  86.             smoothPointCloud.Add(pointList[i]);
  87.             //smoothPointCloud.Add(pointList[i]);
  88.             basePlaneDirection = NormalizedNewvector;
  89.         }
  90.     }
  91.  
  92.     smoothPointCloud.Shrink();
  93.  
  94.  
  95.     return smoothPointCloud;
  96. }
  97.  
  98. //Parse the read file to an array of Point vectors.
  99. TArray<FVector> PointcloudSmoothener::constructPointVectors(TArray<FString> data)
  100. {
  101.     //fprintf(stderr, "%s", data.c_str());
  102.     TArray<FVector> points;//Size = 2 * numLines + 2.
  103.     TArray<std::string> floats;//Size = 2 * numLines + 2.
  104.  
  105.     size_t pos = 0;
  106.     size_t prev = 0;
  107.     std::string token;
  108.    
  109.     //Split into Floats
  110.     std::string delimiter =  " ";
  111.     for (int i = 0; i < data.Num(); i++) {
  112.         std::string currLine = std::string(TCHAR_TO_UTF8(*data[i]));
  113.         while ((pos = currLine.find(delimiter, prev)) != std::string::npos) {
  114.             token = currLine.substr(prev, pos - prev);
  115.             //fprintf(stderr, "%s\n", token.c_str());
  116.             floats.Add(token);
  117.             prev = pos + delimiter.size();
  118.         }
  119.         //Save the last flaots
  120.         token = currLine.substr(prev, pos - prev);
  121.         floats.Add(token);
  122.     }
  123.     //fprintf(stderr, "floats.size = %d", floats.Num());
  124.  
  125.     //Parse all floats and save them
  126.     for (int i = 0; i < floats.Num(); i += 2) {
  127.         points.Add(FVector((float)::atof(floats[i].c_str()) / 1000.0f, 0.0f, (float)::atof(floats[i + 1].c_str()) / 1000.0f));
  128.         //fprintf(stderr, "%f %f \n", (float)::atof(floats[i].c_str()), (float)::atof(floats[i+1].c_str()));
  129.     }
  130.  
  131.     return points;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment