// File: /workspace/github_c_makefile_star2_O3/zpole[P]IICV/vl/covdet.c
// Function: vl_covdet_new
VlCovDet *
vl_covdet_new (VlCovDetMethod method)
{
  VlCovDet * self = vl_calloc(sizeof(VlCovDet),1) ;
  self->method = method ;
  self->octaveResolution = 3 ;
  self->firstOctave = -1 ;
  switch (self->method) {
    case VL_COVDET_METHOD_DOG :
      self->peakThreshold = VL_COVDET_DOG_DEF_PEAK_THRESHOLD ;
      self->edgeThreshold = VL_COVDET_DOG_DEF_EDGE_THRESHOLD ;
      self->lapPeakThreshold = 0  ; /* not used */
      break ;
    case VL_COVDET_METHOD_HARRIS_LAPLACE:
    case VL_COVDET_METHOD_MULTISCALE_HARRIS:
      self->peakThreshold = VL_COVDET_HARRIS_DEF_PEAK_THRESHOLD ;
      self->edgeThreshold = VL_COVDET_HARRIS_DEF_EDGE_THRESHOLD ;
      self->lapPeakThreshold = VL_COVDET_LAP_DEF_PEAK_THRESHOLD ;
      break ;
    case VL_COVDET_METHOD_HESSIAN :
    case VL_COVDET_METHOD_HESSIAN_LAPLACE:
    case VL_COVDET_METHOD_MULTISCALE_HESSIAN:
      self->peakThreshold = VL_COVDET_HESSIAN_DEF_PEAK_THRESHOLD ;
      self->edgeThreshold = VL_COVDET_HESSIAN_DEF_EDGE_THRESHOLD ;
      self->lapPeakThreshold = VL_COVDET_LAP_DEF_PEAK_THRESHOLD ;
      break;
    default:
      assert(0) ;
  }

  self->nonExtremaSuppression = 0.5 ;
  self->features = NULL ;
  self->numFeatures = 0 ;
  self->numFeatureBufferSize = 0 ;
  self->patch = NULL ;
  self->patchBufferSize = 0 ;
  self->transposed = VL_FALSE ;
  self->aaAccurateSmoothing = VL_COVDET_AA_ACCURATE_SMOOTHING ;

  {
    vl_index const w = VL_COVDET_AA_PATCH_RESOLUTION ;
    vl_index i,j ;
    double step = (2.0 * VL_COVDET_AA_PATCH_EXTENT) / (2*w+1) ;
    double sigma = VL_COVDET_AA_RELATIVE_INTEGRATION_SIGMA ;
    for (j = -w ; j <= w ; ++j) {
      for (i = -w ; i <= w ; ++i) {
        double dx = i*step/sigma ;
        double dy = j*step/sigma ;
        self->aaMask[(i+w) + (2*w+1)*(j+w)] = exp(-0.5*(dx*dx+dy*dy)) ;
      }
    }
  }

  {
    /*
     Covers one octave of Laplacian filters, from sigma=1 to sigma=2.
     The spatial sampling step is 0.5.
     */
    vl_index s ;
    for (s = 0 ; s < VL_COVDET_LAP_NUM_LEVELS ; ++s) {
      double sigmaLap = pow(2.0, -0.5 +
                            (double)s / (VL_COVDET_LAP_NUM_LEVELS - 1)) ;
      double const sigmaImage = 1.0 / sqrt(2.0) ;
      double const step = 0.5 * sigmaImage ;
      double const sigmaDelta = sqrt(sigmaLap*sigmaLap - sigmaImage*sigmaImage) ;
      vl_size const w = VL_COVDET_LAP_PATCH_RESOLUTION ;
      vl_size const num = 2 * w + 1  ;
      float * pt = self->laplacians + s * (num * num) ;

      memset(pt, 0, num * num * sizeof(float)) ;

#define at(x,y) pt[(x+w)+(y+w)*(2*w+1)]
      at(0,0) = - 4.0 ;
      at(-1,0) = 1.0 ;
      at(+1,0) = 1.0 ;
      at(0,1) = 1.0 ;
      at(0,-1) = 1.0 ;
#undef at

      vl_imsmooth_f(pt, num,
                    pt, num, num, num,
                    sigmaDelta / step, sigmaDelta / step) ;

#if 0
      {
        char name [200] ;
        snprintf(name, 200, "/tmp/%f-lap.pgm", sigmaDelta) ;
        vl_pgm_write_f(name, pt, num, num) ;
      }
#endif

    }
  }
  return self ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edi, %ebp
movl $0x12568, %edi          # imm = 0x12568
movl $0x1, %esi
callq 0x98f0
movq %rax, %rbx
movl %ebp, 0x10(%rax)
movq $0x3, 0x30(%rax)
movq $-0x1, 0x38(%rax)
decl %ebp
cmpl $0x5, %ebp
ja 0xbc2a
movl %ebp, %eax
leaq 0x266f7(%rip), %rcx     # 0x322f8
movsd (%rcx,%rax,8), %xmm0
leaq 0x2671b(%rip), %rcx     # 0x32328
movsd (%rcx,%rax,8), %xmm1
movsd %xmm0, 0x18(%rbx)
movabsq $0x4024000000000000, %rax # imm = 0x4024000000000000
movq %rax, 0x20(%rbx)
movsd %xmm1, 0x28(%rbx)
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, 0x40(%rbx)
movl $0x0, 0x100(%rbx)
leaq 0x4fd0(%rbx), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rbx)
movups %xmm0, 0x60(%rbx)
movups %xmm0, 0x6c(%rbx)
movq $-0x14, %r15
movsd 0x265b1(%rip), %xmm2    # 0x32218
movsd 0x265b1(%rip), %xmm3    # 0x32220
movsd 0x265b1(%rip), %xmm1    # 0x32228
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
mulsd %xmm2, %xmm0
divsd %xmm3, %xmm0
mulsd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r12d, %r12d
leaq -0x14(%r12), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd %xmm2, %xmm0
divsd %xmm3, %xmm0
mulsd %xmm0, %xmm0
addsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
callq 0x9a60
movsd 0x2655c(%rip), %xmm3    # 0x32220
movsd 0x2654c(%rip), %xmm2    # 0x32218
movsd 0x26554(%rip), %xmm1    # 0x32228
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r14,%r12,4)
incq %r12
cmpq $0x29, %r12
jne 0xbc94
incq %r15
addq $0xa4, %r14
cmpq $0x15, %r15
jne 0xbc77
movq %rbx, %r14
addq $0x7b18, %r14           # imm = 0x7B18
xorl %r15d, %r15d
movl $0x3f800000, %ebp       # imm = 0x3F800000
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
divsd 0x26517(%rip), %xmm0    # 0x32230
addsd %xmm1, %xmm0
callq 0x9040
mulsd %xmm0, %xmm0
addsd 0x2650a(%rip), %xmm0    # 0x32238
ucomisd 0x262fa(%rip), %xmm0    # 0x32030
jb 0xbd3e
sqrtsd %xmm0, %xmm0
jmp 0xbd43
callq 0x9990
movsd %xmm0, 0x8(%rsp)
movl $0x1104, %edx           # imm = 0x1104
movq %r14, %rdi
xorl %esi, %esi
callq 0x9400
movsd 0x263b0(%rip), %xmm0    # 0x32110
movsd %xmm0, 0x87c(%r14)
movl %ebp, 0x884(%r14)
movl %ebp, 0x904(%r14)
movl %ebp, 0x7fc(%r14)
movsd 0x8(%rsp), %xmm0
divsd 0x264b4(%rip), %xmm0    # 0x32240
movl $0x21, %esi
movl $0x21, %ecx
movl $0x21, %r8d
movl $0x21, %r9d
movq %r14, %rdi
movq %r14, %rdx
movapd %xmm0, %xmm1
callq 0x9770
incq %r15
addq $0x1104, %r14           # imm = 0x1104
cmpq $0xa, %r15
movsd 0x26461(%rip), %xmm1    # 0x32228
jne 0xbd09
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq