コード例 #1
0
BOOL LASwriterTXT::open(FILE* file, const LASheader* header, const char* parse_string, const char* separator)
{
  if (file == 0)
  {
    fprintf(stderr,"ERROR: file pointer is zero\n");
    return FALSE;
  }

  this->file = file;
  this->header = header;

  if (parse_string)
  {
    this->parse_string = strdup(parse_string);
  }
  else
  {
    if (header->point_data_format == 1 || header->point_data_format == 4)
    {
      this->parse_string = strdup("xyzt");
    }
    else if (header->point_data_format == 2)
    {
      this->parse_string = strdup("xyzRGB");
    }
    else if (header->point_data_format == 3 || header->point_data_format == 5)
    {
      this->parse_string = strdup("xyztRGB");
    }
    else
    {
      this->parse_string = strdup("xyz");
    }
  }

  if (!check_parse_string(this->parse_string))
  {
    return FALSE;
  }

  if (separator)
  {
    if (strcmp(separator, "comma") == 0)
    {
      separator_sign = ',';
    }
    else if (strcmp(separator, "tab") == 0)
    {
      separator_sign = '\t';
    }
    else if (strcmp(separator, "dot") == 0 || strcmp(separator, "period") == 0)
    {
      separator_sign = '.';
    }
    else if (strcmp(separator, "colon") == 0)
    {
      separator_sign = ':';
    }
    else if (strcmp(separator, "semicolon") == 0)
    {
      separator_sign = ';';
    }
    else if (strcmp(separator, "hyphen") == 0 || strcmp(separator, "minus") == 0)
    {
      separator_sign = '-';
    }
    else if (strcmp(separator, "space") == 0)
    {
      separator_sign = ' ';
    }
    else
    {
      fprintf(stderr, "ERROR: unknown seperator '%s'\n", separator);
      return FALSE;
    }
  }

  return TRUE;
}
コード例 #2
0
ファイル: laswriter_txt.cpp プロジェクト: pesci2k/LAStools
BOOL LASwriterTXT::open(FILE* file, const LASheader* header, const CHAR* parse_string, const CHAR* separator)
{
  if (file == 0)
  {
    fprintf(stderr,"ERROR: file pointer is zero\n");
    return FALSE;
  }

  this->file = file;
  this->header = header;

  if (this->parse_string) free (this->parse_string);
  if (parse_string)
  {
    this->parse_string = strdup(parse_string);
  }
  else
  {
    this->parse_string = 0;
  }

  if (separator)
  {
    if (strcmp(separator, "comma") == 0)
    {
      separator_sign = ',';
    }
    else if (strcmp(separator, "tab") == 0)
    {
      separator_sign = '\t';
    }
    else if (strcmp(separator, "dot") == 0 || strcmp(separator, "period") == 0)
    {
      separator_sign = '.';
    }
    else if (strcmp(separator, "colon") == 0)
    {
      separator_sign = ':';
    }
    else if (strcmp(separator, "semicolon") == 0)
    {
      separator_sign = ';';
    }
    else if (strcmp(separator, "hyphen") == 0 || strcmp(separator, "minus") == 0)
    {
      separator_sign = '-';
    }
    else if (strcmp(separator, "space") == 0)
    {
      separator_sign = ' ';
    }
    else
    {
      fprintf(stderr, "ERROR: unknown seperator '%s'\n", separator);
      return FALSE;
    }
  }

  if (opts)
  {
    // look for VRL with PTS or PTX info
    const LASvlr* ptsVLR = 0;
    const LASvlr* ptxVLR = 0;
    if ((ptsVLR = header->get_vlr("LAStools", 2000)) || (ptxVLR = header->get_vlr("LAStools", 2001)))
    {
      if ((this->parse_string == 0) || (strcmp(this->parse_string, "original") == 0))
      {
        if (this->parse_string) free(this->parse_string);
        if (ptsVLR && (ptsVLR->record_length_after_header >= 32))
        {
          this->parse_string = strdup((CHAR*)(ptsVLR->data + 16));
        }
        else if (ptxVLR && (ptxVLR->record_length_after_header >= 32))
        {
          this->parse_string = strdup((CHAR*)(ptxVLR->data + 16));
        }
        else if (ptsVLR)
        {
          fprintf(stderr, "WARNING: found VLR for PTS with wrong payload size of %d.\n", ptsVLR->record_length_after_header);
        }
        else if (ptxVLR)
        {
          fprintf(stderr, "WARNING: found VLR for PTX with wrong payload size of %d.\n", ptxVLR->record_length_after_header);
        }
      }
    }
    else
    {
      fprintf(stderr, "WARNING: found no VLR with PTS or PTX info.\n");
    }
    if (header->version_minor >= 4)
    {
#ifdef _WIN32
      fprintf(file, "%I64d       \012", header->extended_number_of_point_records);
#else
      fprintf(file, "%lld       \012", header->extended_number_of_point_records);
#endif
    }
    else
    {
      fprintf(file, "%u       \012", header->number_of_point_records);
    }
    if (this->parse_string && strcmp(this->parse_string, "xyz") && strcmp(this->parse_string, "xyzi") && strcmp(this->parse_string, "xyziRGB") && strcmp(this->parse_string, "xyzRGB"))
    {
      fprintf(stderr, "WARNING: the parse string for PTS should be 'xyz', 'xyzi', 'xyziRGB', or 'xyzRGB'\n");
    }
    if (separator_sign != ' ')
    {
      fprintf(stderr, "WARNING: the separator for PTS should be 'space' not '%s'\n", separator);
    }
  }
  else if (optx)
  {
    // look for VRL with PTX info
    const LASvlr* ptxVLR = header->get_vlr("LAStools", 2001);
    if (ptxVLR && (ptxVLR->record_length_after_header == 272))
    {
      U8* payload = ptxVLR->data;
      if ((this->parse_string == 0) || (strcmp(this->parse_string, "original") == 0))
      {
        if (this->parse_string) free(this->parse_string);
        this->parse_string = strdup((CHAR*)(payload + 16));
      }
      fprintf(file, "%u     \012", (U32)((I64*)payload)[4]); // ncols
      fprintf(file, "%u     \012", (U32)((I64*)payload)[5]); // nrows
      fprintf(file, "%g %g %g\012", ((F64*)payload)[6], ((F64*)payload)[7], ((F64*)payload)[8]); // translation
      fprintf(file, "%g %g %g\012", ((F64*)payload)[9], ((F64*)payload)[10], ((F64*)payload)[11]); // rotation_row_0
      fprintf(file, "%g %g %g\012", ((F64*)payload)[12], ((F64*)payload)[13], ((F64*)payload)[14]); // rotation_row_1
      fprintf(file, "%g %g %g\012", ((F64*)payload)[15], ((F64*)payload)[16], ((F64*)payload)[17]); // rotation_row_2
      fprintf(file, "%g %g %g %g\012", ((F64*)payload)[18], ((F64*)payload)[19], ((F64*)payload)[20], ((F64*)payload)[21]); // transformation_row_0
      fprintf(file, "%g %g %g %g\012", ((F64*)payload)[22], ((F64*)payload)[23], ((F64*)payload)[24], ((F64*)payload)[25]); // transformation_row_0
      fprintf(file, "%g %g %g %g\012", ((F64*)payload)[26], ((F64*)payload)[27], ((F64*)payload)[28], ((F64*)payload)[29]); // transformation_row_0
      fprintf(file, "%g %g %g %g\012", ((F64*)payload)[30], ((F64*)payload)[31], ((F64*)payload)[32], ((F64*)payload)[33]); // transformation_row_0
    }
    else
    {
      if (ptxVLR)
      {
        fprintf(stderr, "WARNING: found VLR for PTX with wrong payload size of %d.\n", ptxVLR->record_length_after_header);
      }
      else
      {
        fprintf(stderr, "WARNING: found no VLR with PTX info.\n");
      }
      fprintf(stderr, "         outputting PTS instead ...\n");
      if (header->version_minor >= 4)
      {
#ifdef _WIN32
        fprintf(file, "%I64d       \012", header->extended_number_of_point_records);
#else
        fprintf(file, "%lld       \012", header->extended_number_of_point_records);
#endif
      }
      else
      {
        fprintf(file, "%u       \012", header->number_of_point_records);
      }
    }
    if (this->parse_string && strcmp(this->parse_string, "xyz") && strcmp(this->parse_string, "xyzi") && strcmp(this->parse_string, "xyziRGB") && strcmp(this->parse_string, "xyzRGB"))
    {
      fprintf(stderr, "WARNING: the parse string for PTX should be 'xyz', 'xyzi', 'xyziRGB', or 'xyzRGB'\n");
    }
    if (separator_sign != ' ')
    {
      fprintf(stderr, "WARNING: the separator for PTX should be 'space' not '%s'\n", separator);
    }
  }

  if (this->parse_string == 0)
  {
    if (header->point_data_format == 1 || header->point_data_format == 4)
    {
      this->parse_string = strdup("xyzt");
    }
    else if (header->point_data_format == 2)
    {
      this->parse_string = strdup("xyzRGB");
    }
    else if (header->point_data_format == 3 || header->point_data_format == 5)
    {
      this->parse_string = strdup("xyztRGB");
    }
    else
    {
      this->parse_string = strdup("xyz");
    }
  }

  return check_parse_string(this->parse_string);
}