Esempio n. 1
0
void Button::DrawSelf()
{
	const float opacity = Opacity();
	glColor4f(0.8f, 0.8f, 0.8f, opacity);
	
	DrawBox(GL_QUADS);
	
	glColor4f(1.0f, 1.0f, 1.0f, 0.1f);
	if (clicked) {
		glBlendFunc(GL_ONE, GL_ONE); // additive blending
		glColor4f(0.2f, 0.0f, 0.0f, opacity);
		DrawBox(GL_QUADS);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(1.0f, 0.0f, 0.0f, opacity/2.f);
		glLineWidth(1.49f);
		DrawBox(GL_LINE_LOOP);
		glLineWidth(1.0f);
	} else if (hovered) {
		glBlendFunc(GL_ONE, GL_ONE); // additive blending
		glColor4f(0.0f, 0.0f, 0.2f, opacity);
		DrawBox(GL_QUADS);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(1.0f, 1.0f, 1.0f, opacity/2.0f);
		glLineWidth(1.49f);
		DrawBox(GL_LINE_LOOP);
		glLineWidth(1.0f);
	}

	font->Begin();
	font->SetTextColor(1.0f, 1.0f, 1.0f, opacity);
	font->SetOutlineColor(0.0f, 0.0f, 0.0f, opacity);
	font->glPrint(pos[0] + size[0]/2, pos[1] + size[1]/2, 1.0, FONT_CENTER | FONT_VCENTER | FONT_SHADOW | FONT_SCALE | FONT_NORM, label);
	font->End();
}
Esempio n. 2
0
void Window::DrawSelf()
{
	const float opacity = Opacity();
	glColor4f(0.0f,0.0f,0.0f, opacity);
	DrawBox(GL_QUADS);

	glColor4f(0.7f,0.7f,0.7f, opacity);
	glBegin(GL_QUADS);
	glVertex2f(pos[0], pos[1]+size[1]-titleHeight);
	glVertex2f(pos[0], pos[1]+size[1]);
	glVertex2f(pos[0]+size[0], pos[1]+size[1]);
	glVertex2f(pos[0]+size[0], pos[1]+size[1]-titleHeight);
	glEnd();

	glLineWidth(2.0f);
	glColor4f(1.0f,1.0f,1.0f, opacity);
	DrawBox(GL_LINE_LOOP);
	/*
	glBegin(GL_LINE);
	glVertex2f(pos[0], pos[1]-titleHeight);
	glVertex2f(pos[0]+size[1], pos[1]-titleHeight);
	glEnd();*/

	font->Begin();
	font->SetTextColor(1.0f, 1.0f, 1.0f, opacity);
	font->SetOutlineColor(0.0f, 0.0f, 0.0f, opacity);
	font->glPrint(pos[0]+0.01, pos[1]+size[1]-titleHeight/2, 1.0, FONT_VCENTER | FONT_SCALE | FONT_SHADOW | FONT_NORM, title);
	font->End();
}
void HorizontalLayout::DrawSelf()
{
	if (borderWidth > 0)
	{
		glLineWidth(borderWidth);
		glColor4f(1.f,1.f,1.f, Opacity());
		DrawBox(GL_LINE_LOOP);
	}
}
Esempio n. 4
0
MicroPolygon::MicroPolygon()
{
  p[0]=Point3(0,0,0);
  p[1]=Point3(0,0,0);
  p[2]=Point3(0,0,0);
  p[3]=Point3(0,0,0);
  colour=Colour(0,0,0);
  opacity=Opacity(1,1,1);
}
Esempio n. 5
0
void Sprite::BlitScreenIntern(Bitmap const& draw_bitmap,
								Rect const& src_rect, int opacity_split) const {
	BitmapRef dst = DisplayUi->GetDisplaySurface();

	double zoom_x = zoom_x_effect;
	double zoom_y = zoom_y_effect;

	dst->EffectsBlit(x, y, ox, oy, draw_bitmap, src_rect,
					 Opacity(opacity_top_effect, opacity_bottom_effect, opacity_split),
					 zoom_x, zoom_y, angle_effect != 0.0 ? angle_effect * 3.14159 / 180 : 0.0,
					 waver_effect_depth, waver_effect_phase);
}
Esempio n. 6
0
void LineEdit::DrawSelf()
{
    const float opacity = Opacity();
    glColor4f(1.0f,1.0f,1.0f, opacity);
    DrawBox(GL_QUADS);

    glLineWidth(1.49f);
    if (hasFocus)
    {
        glColor4f(0.0f,0.0f,0.0f, opacity);
        DrawBox(GL_LINE_LOOP);
    }
    else
    {
        glColor4f(0.5f,0.5f,0.5f, opacity);
        DrawBox(GL_LINE_LOOP);
    }

    std::string tempText;
    if (crypt)
    {
        tempText.resize(content.size(), '*');
    }
    else
        tempText = content;

    const float textCenter = pos[1]+size[1]/2;
    if (hasFocus)
    {
        // draw the caret
        const std::string caretStr = tempText.substr(0, cursorPos);
        const float caretWidth = font->GetSize() * font->GetTextWidth(caretStr) / float(screensize[0]);

        char c = tempText[cursorPos];
        if (c == 0) {
            c = ' ';
        }

        const float cursorHeight = font->GetSize() * font->GetLineHeight() / float(screensize[1]);
        const float cw = font->GetSize() * font->GetCharacterWidth(c) /float(screensize[0]);
        const float csx = pos[0]+0.01 + caretWidth;
        const float f = 0.5f * (1.0f + fastmath::sin((float)SDL_GetTicks() * 0.015f));
        glColor4f(f, f, f, opacity);
        glRectf(csx, textCenter + cursorHeight/2, csx + cw, textCenter - cursorHeight/2);
        glColor4f(0.0f,0.0f,0.0f, 1.0f); // black
    }

    font->SetTextColor(); //default
    font->glPrint(pos[0]+0.01, textCenter, 1.0, FONT_VCENTER | FONT_SCALE | FONT_NORM, tempText);
}
// Draws the two shadow sprites to a single intermediate bitmap to be blit to the map
// Needs to be recalled when the System graphic changes
void Sprite_AirshipShadow::RecreateShadow() {
	GetBitmap()->Clear();

	std::string system_name = Game_System::GetSystemName();
	if (system_name.empty()) return;

	BitmapRef system = Cache::System(system_name);

	// Offset of the shadow in the System graphic as per
	// https://easy-rpg.org/wiki/development/technical-details/system-graphics
	// TODO 26% opacity looks okay, but isn't accurate to RPG_RT
	Opacity opacity = Opacity(0.26 * 255);
	GetBitmap()->Blit(0, 0, *system, Rect(128,32,16,16), opacity);
	GetBitmap()->Blit(0, 0, *system, Rect(128+16,32,16,16), opacity);
}
IFXRESULT CIFXShaderLitTexture::RenderShaderLitTexture( IFXRenderContext& rInRenderer )
{
	IFXRESULT result = IFX_OK;

	BOOL bMaterialTransparent = FALSE;

	if ( !m_pSceneGraph )
		return IFX_E_NOT_INITIALIZED;

	// Mode
	if ( m_uFlags & FLAT )
		m_Material.SetShadeModel(IFX_FLAT);
	else
		m_Material.SetShadeModel(IFX_SMOOTH);

	if ( m_uFlags & WIRE )
		m_Material.SetRenderStyle(IFX_WIREFRAME);
	else if ( m_uFlags & POINT )
		m_Material.SetRenderStyle(IFX_POINTS);
	else
		m_Material.SetRenderStyle(IFX_FILLED);

	// Materials
	IFXMaterialResource* pMaterialResource = NULL;
	if ( m_uFlags & MATERIAL )
	{
		IFXPalette* pPalette = NULL;
		result = m_pSceneGraph->GetPalette( IFXSceneGraph::MATERIAL, &pPalette );

		if ( IFXSUCCESS( result ) )
		{
			result = pPalette->GetResourcePtr( m_uMaterialID, 
				IID_IFXMaterialResource, 
				(void**)&pMaterialResource );
			if ( IFXFAILURE( result ) )
				result = pPalette->GetResourcePtr( 0, 
				IID_IFXMaterialResource, 
				(void**)&pMaterialResource );
		}

		if ( pMaterialResource )
		{
			pMaterialResource->GetTransparent(&bMaterialTransparent);

			// Set up the emmisive color
			IFXVector4 color;
			if ( IFXSUCCESS( result ) )
				result = pMaterialResource->GetEmission(&color);

			if ( IFXSUCCESS( result ) )
				result = m_Material.SetEmissive(*(IFXVector4*)&color.R());

			// Set up the ambient color
			if ( IFXSUCCESS( result ) )
				result = pMaterialResource->GetAmbient(&color);
			if ( IFXSUCCESS( result ) )
				result = m_Material.SetAmbient(*(IFXVector4*)&color.R());

			// Set up the diffuse color
			if ( IFXSUCCESS(result) )
				result = pMaterialResource->GetDiffuse(&color);
			if ( IFXSUCCESS( result ) )
				result = pMaterialResource->GetOpacity(&(color.H()));
			if ( IFXSUCCESS( result ) )
				result = m_Material.SetDiffuse(*(IFXVector4*)&color.R());

			// Set up the specular color
			if ( IFXSUCCESS( result ) )
				result = pMaterialResource->GetSpecular(&color);
			if ( IFXSUCCESS( result ) )
				result = m_Material.SetSpecular(*(IFXVector4*)&color.R());

			// Set up the shinyness
			F32 reflectivity;
			if ( IFXSUCCESS( result ) )
				result = pMaterialResource->GetReflectivity(&reflectivity);
			if ( IFXSUCCESS( result ) )
			{
				if ( reflectivity > 1.0f )
					result = m_Material.SetShininess(1.0f);
				else
					result = m_Material.SetShininess(reflectivity);
			}
		}
		IFXRELEASE(pPalette);
	}

	// Textures
	IFXPalette* pPalette = NULL;
	if( IFXSUCCESS(result) )
		result = m_pSceneGraph->GetPalette( IFXSceneGraph::TEXTURE, &pPalette);

	BOOL bTextures = FALSE;
	U32 i;
	//IFXMatrix4x4 mTrans;
	U32 uMaxTexUnit = 0;
	for ( i=0; i<IFX_MAX_TEXUNITS; i++ ) 
	{
		if ( m_uChannels & (1<<i) )
		{
			uMaxTexUnit = i+1;
			IFXTextureObject* pTextureObject = NULL;
			if ( IFXSUCCESS( result ) )
				result = pPalette->GetResourcePtr( m_uTextureID[i], 
				IID_IFXTextureObject, 
				(void**)&pTextureObject );

			if ( IFXSUCCESS( result ) )
			{
				//result = pTextureObject->UpdateAndMakeCurrent(pInRenderContext, i);
				result = rInRenderer.SetTexture(*pTextureObject);
				if (result == IFX_W_READING_NOT_COMPLETE) result = IFX_E_NOT_INITIALIZED;
				IFXRUN(result, m_pTexUnits[i].SetTextureId(pTextureObject->GetId()));
				IFXRELEASE( pTextureObject );

				// Report this to the output window and mask it internally so that
				// the rendered result is untextured instead of not rendering at all.
				if (IFXFAILURE(result))
				{
					IFXTRACE_CUSTOM( IFXRESULT_COMPONENT_SCENEGRAPH, 
						IFXDEBUG_MESSAGE, 
						L"UpdateAndMakeCurrent failed in IFXShaderLitTexture:(%p)\n", 
						this);
					result = IFX_OK;
					rInRenderer.Disable(IFX_TEXUNIT0 + i);
				}
				else
				{
					bTextures = TRUE;

					rInRenderer.Enable(IFX_TEXUNIT0 + i);

					if( m_uTextureRepeat[i] & IFX_TEXTURE_REPEAT_1 )
					{
						m_pTexUnits[i].SetTexRepeatU( TRUE );
					}
					else
					{
						m_pTexUnits[i].SetTexRepeatU( FALSE );
					}

					if( m_uTextureRepeat[i] & IFX_TEXTURE_REPEAT_2 )
					{
						m_pTexUnits[i].SetTexRepeatV( TRUE );
					}
					else
					{
						m_pTexUnits[i].SetTexRepeatV( FALSE );
					}
				}
			}

			if (  (result == IFX_E_PALETTE_NULL_RESOURCE_POINTER )
				||(result == IFX_E_INVALID_RANGE ) )
				result = IFX_OK;

			if( IFXSUCCESS( result ) )
			{
				F32 reflectivity = 1;
				if ( pMaterialResource && IFXSUCCESS( result ) )
					result = pMaterialResource->GetReflectivity(&reflectivity);
				if ( IFXSUCCESS( result ) )
				{
					if ( reflectivity > 1.0f )
					{
						m_sUVMapperParams[i].fShininess = 1.0f;
					}
					else
					{
						m_sUVMapperParams[i].fShininess = reflectivity;
					}
				}

				if( m_pUVMapper[i] )
				{
					if(m_bInvertTrans)
					{
						IFXMatrix4x4 mTrans;
						mTrans.Reset();
						if(IFXFAILURE(mTrans.Invert3x4(m_pTexTransforms[i])))
						{
							F32* fMat = m_pTexTransforms[i].Raw();
							fMat[2] = fMat[6] = 0.0f;
							fMat[10] = 1.0f;
							mTrans.Invert3x4(m_pTexTransforms[i]);
						}
						m_pTexUnits[i].SetTextureTransform(mTrans);
					}
					else
					{
						m_pTexUnits[i].SetTextureTransform(m_pTexTransforms[i]);
					}
				}
			}

			UpdateAlphaCacheBits( i, m_uTextureID[i] );
			// NOTE: UpdateAlphaCacheBits() returns an IFXRESULT, but we don't
			// care about it because it's possible that this shader doesn't
			// currently have a texture, in which case it would return an 
			// error because there's no texture in the texture palette at
			// that ID.  However - rest assured that this call will 
			// EITHER SET OR CLEAR the alpha cache bit for that layer (clear if 
			// there's no texture).
		}
		else 
		{
			m_uTexturesWithAlphaChannel &= ~(1<<i);
			rInRenderer.Disable(IFX_TEXUNIT0 + i);
		}

		rInRenderer.SetTextureUnit(IFX_TEXUNIT0 + i, m_pTexUnits[i]);
	}
	IFXRELEASE(pPalette);
	IFXRELEASE(pMaterialResource);

	// UseDiffuseWithTexture
	if ( !(m_uFlags&USEDIFFUSE) && bTextures && IFXSUCCESS( result ) )
	{
		IFXVector4 color = m_Material.GetDiffuse();
		color.R() = 1;
		color.G() = 1;
		color.B() = 1;
		result = m_Material.SetDiffuse(color);
	}
	IFXRUN(result, rInRenderer.SetMaterial(m_Material));

	/// @todo Fix this when dependent transparnecy is implemented.
	//BOOL bTransparent = Opacity() == IFX_SHADER_OPACITY_FALSE;
	BOOL bTransparent = Opacity() == IFX_SHADER_OPACITY_FALSE;
	BOOL bUsingBlending = FALSE;

	// Frame buffer blending
	if ((m_Blend.GetBlendFunc() == IFX_FB_ALPHA_BLEND)
		||(m_Blend.GetBlendFunc() == IFX_FB_INV_ALPHA_BLEND))
	{
		if (bTransparent)
		{
			bUsingBlending = TRUE;
			result = rInRenderer.Enable(IFX_FB_BLEND);
		}
		else
		{
			result = rInRenderer.Disable(IFX_FB_BLEND);
		}
	}
	else if(bMaterialTransparent)
	{
		bUsingBlending = TRUE;
		result = rInRenderer.Enable(IFX_FB_BLEND);
	}
	else 
	{
		result = rInRenderer.Disable(IFX_FB_BLEND);
	}

	if(IFXSUCCESS(result) && m_bAlphaTestEnabled)
	{
		result = rInRenderer.Enable(IFX_FB_ALPHA_TEST);
	}
	else if(IFXSUCCESS(result))
	{
		result = rInRenderer.Disable(IFX_FB_ALPHA_TEST);
	}

	IFXRUN(result, rInRenderer.SetBlend(m_Blend));

	// Lighting
	if (m_bLighting)
	{
		IFXRUN(result, rInRenderer.Enable(IFX_LIGHTING));
	}
	else
	{
		IFXRUN(result, rInRenderer.Disable(IFX_LIGHTING));
	}

	// Render
	U32 uNumPasses = rInRenderer.CalculateNumPasses();
	U32 passNum;
	for( passNum = 0; passNum < uNumPasses && IFXSUCCESS(result); passNum++)
	{
		result = rInRenderer.ConfigureRenderPass(passNum);

		IFXMesh* pMesh;
		IFXMeshGroup* pMeshGroup;
		IFXShadedElement* pElement;
		static IFXListContext context;
		IFXMatrix4x4 renderTransform, offsetTransform;

		m_shadedElementList.ToHead(context);
		const IFXLightSet* pLastLightSet = 0;
		const IFXFrustum* pLastFrustum = 0;
		IFXMatrix4x4 mFrustumInverse;
		mFrustumInverse.Reset();

		while ( (pElement = m_shadedElementList.PostIncrement(context)) && IFXSUCCESS(result))
		{
			if ( IFX_OK == pElement->pDataPacket->
				GetDataElement( pElement->u16DataElementIndex, 
				IID_IFXMeshGroup, 
				(void**)&pMeshGroup ) )
			{
				if ( IFX_OK == pMeshGroup->
					GetMesh( pElement->uRenderableElementIndex, pMesh ) )
				{
					if ((pMesh->GetNumFaces() && m_bDrawFaces)
						||(pMesh->GetNumLines() && m_bDrawLines) || (pMesh->GetNumVertices() && m_bDrawPoints))
					{
						// Lights
						if ( m_bLighting ) 
						{
							if(pElement->pLightSet != pLastLightSet)
							{
								pLastLightSet = pElement->pLightSet;
								static const F32 black[4] = { 0,0,0,0 };
								rInRenderer.SetGlobalAmbient((F32*)black);

								U32 nHardwareLightsUsed = 0;
								const U32 nLights = pElement->pLightSet->GetNumLights();
								U32 lightInstance;
								U32 lightIndex;
								for (  lightIndex = 0; (lightIndex < nLights); lightIndex++ )
								{
									IFXDECLARELOCAL(IFXLight, pLight);
									result = pElement->pLightSet->GetLight(lightIndex, pLight, lightInstance);
									if( IFXSUCCESS(result) && pLight )
									{
										IFXDECLARELOCAL(IFXLightResource, pLR);
										pLR = pLight->GetLightResource();

										if( pLR )
										{
											if ( pLR->GetType() == IFXLightResource::AMBIENT )
												pLight->Enable( &rInRenderer, 0, lightInstance );
											else if ( nHardwareLightsUsed < IFX_MAX_LIGHTS )
												pLight->Enable( &rInRenderer, &nHardwareLightsUsed, lightInstance );
											else
												break; // ...out of the <for> construct.
										}
										else
											break; // ...out of the <for> construct.
									}
								}
								while (nHardwareLightsUsed < IFX_MAX_LIGHTS)
									rInRenderer.Disable( IFX_LIGHT0 + nHardwareLightsUsed++ );
							}
						}

						// Texcoord generation
						if(pLastFrustum != pElement->pFrustum)
						{
							pLastFrustum = pElement->pFrustum;

							mFrustumInverse.Invert3x4(pLastFrustum->GetWorldTransform());
						}
						pMesh->GetOffsetTransform( &offsetTransform );
						renderTransform.Multiply( *(pElement->pfTransform), offsetTransform );

						U32 i;
						for( i = 0; i < uMaxTexUnit; i++)
						{
							result = m_pUVMapper[i]->Generate(	*pMesh, &m_sUVMapperParams[i], 
								&renderTransform, 
								&mFrustumInverse, 
								pElement->pLightSet);
						}

						rInRenderer.SetWorldMatrix( renderTransform );
					}

					if(pMesh->GetNumFaces() && m_bDrawFaces && IFXSUCCESS(result))
					{
						// Two sided and negativly scaled lighting support
						U32 bFrontFaceWindingOrder = 1 - pElement->pfTransform->NegativelyScaled();

						if( (pElement->u16Flags & (1 << 15)) || bUsingBlending)
							rInRenderer.Disable(IFX_DEPTH_WRITE);
						else
							rInRenderer.Enable(IFX_DEPTH_WRITE);

						switch (pElement->u16Flags&3)
						{
						case (1<<FRONT_FACE_VISIBILITY):
							{
								result = rInRenderer.SetCullMode( IFX_CULL_CCW - bFrontFaceWindingOrder );
								IFXRUN(result, rInRenderer.DrawMesh( *pMesh ));
								break;
							}

						case (1<<BACK_FACE_VISIBILITY):
							{
								result = rInRenderer.SetCullMode( IFX_CULL_CW + bFrontFaceWindingOrder );
								if ( bFrontFaceWindingOrder )
									pMesh->ReverseNormals();
								IFXRUN(result, rInRenderer.DrawMesh( *pMesh ));
								if ( bFrontFaceWindingOrder )
									pMesh->ReverseNormals();
								break;
							}

						case ((1<<FRONT_FACE_VISIBILITY) | (1<<BACK_FACE_VISIBILITY)):
							{
								result = rInRenderer.SetCullMode( IFX_CULL_CW + bFrontFaceWindingOrder );
								if ( bFrontFaceWindingOrder && pMesh->GetAttributes().m_uData.m_bHasNormals )
									pMesh->ReverseNormals();
								IFXRUN(result, rInRenderer.DrawMesh( *pMesh ));
								if ( bFrontFaceWindingOrder && pMesh->GetAttributes().m_uData.m_bHasNormals )
									pMesh->ReverseNormals();

								IFXRUN(result, rInRenderer.SetCullMode( IFX_CULL_CCW - bFrontFaceWindingOrder ));
								IFXRUN(result, rInRenderer.DrawMesh( *pMesh ));
								break;
							}

						case 0: // This case should be filtered at a higher level.
						default:
							IFXASSERT(0);
						}
						rInRenderer.SetCullMode( IFX_CULL_CW );
					}

					if(pMesh->GetNumLines() && m_bDrawLines && IFXSUCCESS(result))
						result = rInRenderer.DrawMeshLines( *pMesh );

					if(pMesh->GetNumVertices() && m_bDrawPoints && 
						(pMesh->GetNumFaces() == 0) && (pMesh->GetNumLines()==0)
						&& IFXSUCCESS(result))
					{
						result = rInRenderer.DrawMeshPoints( *pMesh ); 					}

					pMesh->Release();
				}

				pMeshGroup->Release();
			}
		}
	}

	return result;
}
Esempio n. 9
0
void writeOpacity(void)
{
  const char routineName[] = "writeOpacity";
  register int nspect, mu;

  bool_t  to_obs, initialize, crosscoupling, boundbound, polarized,
    PRD_angle_dep, result = TRUE;
  long    Nspace = atmos.Nspace;
  int     record, *as_rn, Nrecord;
  FILE   *fp_out;
  XDR     xdrs;
  ActiveSet *as;

  if (!strcmp(input.opac_output, "none")) return;

  if ((fp_out = fopen(input.opac_output, "w")) == NULL) {
    sprintf(messageStr, "Unable to open output file %s",
	    input.opac_output);
    Error(ERROR_LEVEL_1, routineName, messageStr);
    return;
  }
  xdrstdio_create(&xdrs, fp_out, XDR_ENCODE);

  if (atmos.moving || atmos.Stokes ||
      (atmos.NPRDactive > 0 && input.PRD_angle_dep == PRD_ANGLE_DEP))
    Nrecord = atmos.Nrays*spectrum.Nspect;
  else
    Nrecord = spectrum.Nspect;
  as_rn = (int *) malloc(Nrecord * sizeof(int));

  record = -1;
  for (nspect = 0;  nspect < spectrum.Nspect;  nspect++) {
    as = &spectrum.as[nspect];

    if (containsActive(as)) {
      alloc_as(nspect, crosscoupling=FALSE);

      /* --- Check whether current active set includes a bound-bound
             and/or polarized transition and/or angledependent PRD
             transition. Otherwise, only angle-independent opacity and
             source functions are needed --            -------------- */ 

      boundbound    = containsBoundBound(as);
      PRD_angle_dep = (containsPRDline(as) && input.PRD_angle_dep != PRD_ANGLE_INDEP);
      polarized     = containsPolarized(as);

      /* --- Case of angle-dependent opacity and source function -- - */

      if (polarized || PRD_angle_dep || (atmos.moving && boundbound)) {
	for (mu = 0;  mu < atmos.Nrays;  mu++) {
	  initialize = (mu == 0);
	  Opacity(nspect, mu, to_obs=TRUE, initialize);
	  result &= xdr_vector(&xdrs, (char *) as->chi, Nspace, 
			      sizeof(double), (xdrproc_t) xdr_double);
	  result &= xdr_vector(&xdrs, (char *) as->eta, Nspace, 
			      sizeof(double), (xdrproc_t) xdr_double);
	  as_rn[nspect*atmos.Nrays + mu] = ++record; 
	}
      } else {
	Opacity(nspect, 0, to_obs=TRUE, initialize=TRUE);
	result &= xdr_vector(&xdrs, (char *) as->chi, Nspace, 
			    sizeof(double), (xdrproc_t) xdr_double);
	result &= xdr_vector(&xdrs, (char *) as->eta, Nspace, 
			    sizeof(double), (xdrproc_t) xdr_double);
	if (atmos.moving || atmos.Stokes ||
	    (atmos.NPRDactive > 0 && input.PRD_angle_dep == PRD_ANGLE_DEP)) {
	  record++;
	  for (mu = 0;  mu < atmos.Nrays;  mu++)
	    as_rn[nspect*atmos.Nrays + mu] = record;
	} else
	  as_rn[nspect] = ++record;
      }
      free_as(nspect, crosscoupling=FALSE);
    } else {
      if (atmos.moving || atmos.Stokes ||
	  (atmos.NPRDactive > 0 && input.PRD_angle_dep != PRD_ANGLE_INDEP))
	for (mu = 0;  mu < atmos.Nrays;  mu++)
	  as_rn[nspect*atmos.Nrays + mu] = -1;
      else
	as_rn[nspect] = -1;
    }
  }
  xdr_destroy(&xdrs);
  fclose(fp_out);

  if ((fp_out = fopen(ASRS_DOT_OUT, "w")) == NULL) {
    sprintf(messageStr, "Unable to open output file %s", ASRS_DOT_OUT);
    Error(ERROR_LEVEL_1, routineName, messageStr);
    return;
  }
  xdrstdio_create(&xdrs, fp_out, XDR_ENCODE);

  result &= xdr_vector(&xdrs, (char *) as_rn, Nrecord,
		       sizeof(int), (xdrproc_t) xdr_int);
  free(as_rn);
  xdr_destroy(&xdrs);
  fclose(fp_out);
}
Esempio n. 10
0
File: escape.c Progetto: kouui/rh
/* ------- begin ----------------------------- Escape ------------------- */
void Escape(Atom *atom) {
    /*
      
      Calculates radiative rates using the escape probability approximation

      
      Notes: Escape is inserted in an atom loop. Whatever takes place here should be at
             atom-only level. Why? Because different atoms can have different starting solutions.
             Calling Opacity directly is probably overkill, as it does its own loops, and
             works per wavelength, not per atom.
             
              The line opacity has to be per transition, and thus averaged in wavelength.
              For bound-bound the procedure is the following:
                 
              1. Loop over wavelength to calculate opacity at all wavelengths. Keep an
                 array for each transition, accumulate there the opacity * wla for each
                 transition. (this opacity is depth-dependent as well)
                    
              2. Loop over transitions (and not wavelength!), calculate tau by integrating
                 over depth for each transition
                    
              3. Once we have tau for each transition, add to the gamma of each transition
                 (in the same loop) the nrb recipe.
                    
              For bound-free the procedure is the following:
              
              1. Calculate intensity only for the relevant wavelenths.
              
              2. Using intensity, calculate proper radiative rates and add them to rate matrix.
              
              
    Notes for continuum:

          * To see how rates are added, look at fillgamma.addtoRates or fillgamma.addtoGamma
          * For a simplified version of how to calculate intensity and update rates, look
            at formal.c:233 (the angle-independent case). They could be calculated by a single
            call of Formal, but there is too much rubbish in the main routine, and it could
            call opacity and readbackground more than once -- duplicating many tasks.
      
      
    */
    
    
    const char routineName[] = "Escape";
    register int     n, k, kr, i, ij, ji, nspect;
    int              la, j, nt,  mu, nact;
    double         **opa, *chi, *I, *S, *Psi, *Jdag, *J, tau, wlambda, hc_4PI, twohc,
                     twohnu3_c2, wmu, wlamu, Ieff;
    bool_t           initialize, to_obs;
    ActiveSet       *as;
    AtomicLine      *line;
    AtomicContinuum *continuum;
    
    
    /* --- Some useful constants --                        -------------- */
    hc_4PI = HPLANCK * CLIGHT / (4.0 * PI);
    twohc = 2.0*HPLANCK*CLIGHT / CUBE(NM_TO_M);
    

    opa  = matrix_double(atom->Nline, atmos.Nspace);
    Jdag = (double *) malloc(atmos.Nspace * sizeof(double));
    Psi  = (double *) malloc(atmos.Nspace * sizeof(double));
    chi  = (double *) malloc(atmos.Nspace * sizeof(double));
    I    = (double *) malloc(atmos.Nspace * sizeof(double));
    S    = (double *) malloc(atmos.Nspace * sizeof(double));


    nact = atom->activeindex;
    
    /* Calculate opacities */
    for (nspect = 0;  nspect < spectrum.Nspect;  nspect++) { 
        as = spectrum.as + nspect;
        alloc_as(nspect, FALSE);
        
        nt = nspect % input.Nthreads;

        /* Get line and background opacity */
        Opacity(nspect, 0, to_obs=TRUE, initialize=TRUE); 

	if (input.backgr_in_mem) {
	  loadBackground(nspect, 0, to_obs=TRUE);
	} else {
	  readBackground(nspect, 0, to_obs=TRUE);
	}
        
        /* --- For bound-bound: store opacity in array, per transition -- */
        for (kr = 0; kr < atom->Nline; kr++) {
            line = atom->line + kr;
            la = nspect - line->Nblue;
            
            if (la == 0)
                wlambda = getwlambda_line(line, la);
                
            if ((la >= 0) && (la < line->Nlambda)) {
                /* increment opacities with each wavelength, multiplying by the
                   integration weights */
                for (k = 0 ; k < atmos.Nspace; k++) 
                    opa[kr][k] += (as->chi[k] + as->chi_c[k]) * (wlambda * line->wphi[k] /
                                                                    hc_4PI);
            }
        }
        
        /* --- For bound-free: calculate intensity and update rates ----- */        
        for (n = 0;  n < as->Nactiveatomrt[nact];  n++) {      
            if (as->art[nact][n].type == ATOMIC_CONTINUUM) {
                
                continuum = as->art[nact][n].ptype.continuum;
                la = nspect - continuum->Nblue;
                i = continuum->i;
                j = continuum->j;
                ij = i*atom->Nlevel + j;
                ji = j*atom->Nlevel + i;
                
                twohnu3_c2 = twohc / CUBE(spectrum.lambda[nspect]);
                
                /* Use old J and zero new array */
                if (input.limit_memory) {
                    J = (double *) malloc(atmos.Nspace *sizeof(double));
                    //readJlambda_single(nspect, Jdag);
                } else {
                    J = spectrum.J[nspect];
                    for (k = 0;  k < atmos.Nspace;  k++) Jdag[k] = J[k];
                }
                for (k = 0;  k < atmos.Nspace;  k++) J[k] = 0.0;
                
                for (mu = 0; mu < atmos.Nrays; mu++) {
                    wmu = 0.5 * geometry.wmu[mu];
                        
                    for (k = 0;  k < atmos.Nspace;  k++) {
                        chi[k] = as->chi[k] + as->chi_c[k];
                        S[k]   = (as->eta[k] +
                            as->eta_c[k] + as->sca_c[k]*Jdag[k]) / chi[k];
                    } 
                     
                    /* Get intensity */
                    Piecewise_1D(nspect, mu, to_obs=TRUE, chi, S, I, Psi);
                    
                    /* Update rates */
                    for (k = 0;  k < atmos.Nspace;  k++) {
                        
                        Ieff = I[k] - Psi[k] * atom->rhth[nt].eta[k];
                        wlamu = atom->rhth[nt].Vij[n][k] * atom->rhth[nt].wla[n][k] * wmu;
                        
                        atom->Gamma[ji][k] += Ieff * wlamu;
                        atom->Gamma[ij][k] += (twohnu3_c2 + Ieff) * atom->rhth[nt].gij[n][k] * wlamu;
                        
                        /*  Accumulate mean intensity */
                        J[k] += wmu * I[k];
                    }                    
                }
                if (input.limit_memory) free(J);
            }
        }
        
        free_as(nspect, FALSE);
    }  

    /* Bound-bound: calculate optical depth and add approximation to rates */  
    for (kr = 0; kr < atom->Nline; kr++) {
        line = atom->line + kr;
        i  = line->i;
        j  = line->j;
        ij = i*atom->Nlevel + j;

        tau = 0.0;
        
        for (k = 0; k < atmos.Nspace ; k++) {
            if (k > 0) {
                tau += 0.5*(opa[kr][k-1] + opa[kr][k]) *
                    (geometry.height[k-1] - geometry.height[k]);
            }
            
            /* add escape probability approximation to the rates matrix */
            atom->Gamma[ij][k] += line->Aji * Pesc(tau);   
        }

    }
    
    freeMatrix((void **) opa);
    free(Jdag);
    free(chi);
    free(Psi);
    free(I);
    free(S);
}
Esempio n. 11
0
void List::DrawSelf()
{
	const float opacity = Opacity();
	font->Begin();
	float hf = font->GetSize() / ScaleFactor();

	font->SetTextColor(1,1,0.4f,opacity);

	int nCurIndex = 0; // The item we're on
	int nDrawOffset = 0; // The offset to the first draw item

	GuiElement b;
	b.SetPos(pos[0] + borderSpacing, pos[1] + size[1] - borderSpacing - itemHeight);
	b.SetSize(size[0] - 2.0f * borderSpacing - ((scrollbar.GetSize()[0] < 0) ? 0 : (itemHeight + itemSpacing)), itemHeight);

	// Get list started up here
	std::vector<std::string>::iterator ii = filteredItems->begin();
	// Skip to current selection - 3; ie: scroll
	UpdateTopIndex();

	while (nCurIndex < topIndex) { ++ii; nCurIndex++; }

	const int numDisplay = NumDisplay();

	font->SetTextColor(1.0f, 1.0f, 1.0f, opacity); //default
	font->SetOutlineColor(0.0f, 0.0f, 0.0f, opacity);
	glLineWidth(1.0f);

	float sbX = b.GetPos()[0];
	float sbY1 = b.GetPos()[1] + (itemHeight + itemSpacing);

	for (/*ii = items.begin()*/; ii != filteredItems->end() && nDrawOffset < numDisplay; ++ii)
	{
		glColor4f(1,1,1,opacity/4.f);
		b.DrawBox(GL_LINE_LOOP);

		if (nCurIndex == place) {
			glBlendFunc(GL_ONE, GL_ONE); // additive blending
			glColor4f(0.2f,0,0,opacity);
			b.DrawBox(GL_QUADS);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glColor4f(1,0,0,opacity/2.f);
			glLineWidth(1.49f);
			b.DrawBox(GL_LINE_LOOP);
			glLineWidth(1.0f);
		} else if (b.MouseOver(mx, my)) {
			glBlendFunc(GL_ONE, GL_ONE); // additive blending
			glColor4f(0,0,0.2f,opacity);
			b.DrawBox(GL_QUADS);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glColor4f(1,1,1,opacity/2.f);
			glLineWidth(1.49f);
			b.DrawBox(GL_LINE_LOOP);
			glLineWidth(1.0f);
		}

		font->glPrint(pos[0]+borderSpacing + 0.002f, b.GetMidY() - hf * 0.15f, itemFontScale, FONT_BASELINE | FONT_SHADOW | FONT_SCALE | FONT_NORM, *ii);

		// Up our index's
		nCurIndex++; nDrawOffset++;
		b.Move(0.0,  - (itemHeight + itemSpacing));
	}

	//scrollbar
	if(nDrawOffset < filteredItems->size()) {
		float sbY2 = b.GetPos()[1] + (itemHeight + itemSpacing);
		float sbHeight = sbY1 - sbY2;
		float sbSize = ((float)nDrawOffset / (float)filteredItems->size()) * sbHeight;

		if(activeScrollbar) {
			topIndex = std::max(0, std::min((int)(((float)filteredItems->size() * ((sbY1 - sbSize) - (my - std::min(scrollbarGrabPos, sbSize))) / sbHeight) + 0.5f), 
				(int)filteredItems->size() - numDisplay));
		}

		scrollbar.SetPos(sbX + (size[0] - 2.0f * borderSpacing) - (itemHeight + itemSpacing), 
							sbY1 - sbSize - ((float)topIndex / (float)filteredItems->size()) * sbHeight);
		scrollbar.SetSize((itemHeight + itemSpacing) , sbSize);

		b.SetPos(scrollbar.GetPos()[0], sbY2);
		b.SetSize(itemHeight + itemSpacing, sbHeight);

		glColor4f(1,1,1,opacity/4.f);
		b.DrawBox(GL_LINE_LOOP);

		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(0.8f,0.8f,0.8f,opacity);
		scrollbar.DrawBox(GL_QUADS);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f(1,1,1,opacity/2.f);
		glLineWidth(1.49f);
		scrollbar.DrawBox(GL_LINE_LOOP);
		glLineWidth(1.0f);
	}
	else
		scrollbar.SetSize(-1,-1);
	/**************
	* End insert *
	**************/

	font->End();
}
Esempio n. 12
0
int main(int argc, char *argv[])
{
  register int n, k;

  char    rayFileName[14], inputLine[MAX_LINE_SIZE];
  bool_t  result, exit_on_EOF, to_obs, initialize, crosscoupling,
          analyze_output, equilibria_only;
  int     Nspect, Nread, Nrequired, checkPoint, *wave_index = NULL;
  double  muz, *S, *chi, *J;
  FILE   *fp_out, *fp_ray, *fp_stokes;
  XDR     xdrs;
  ActiveSet *as;

  setOptions(argc, argv);
  getCPU(0, TIME_START, NULL);
  SetFPEtraps();

  /* --- Read input data and initialize --             -------------- */

  readInput();
  spectrum.updateJ = FALSE;

  /* --- Read input data for atmosphere --             -------------- */

  getCPU(1, TIME_START, NULL);
  MULTIatmos(&atmos, &geometry);

  /* --- Read direction cosine for ray --              -------------- */

  if ((fp_ray = fopen(RAY_INPUT_FILE, "r")) == NULL) {
    sprintf(messageStr, "Unable to open inputfile %s", RAY_INPUT_FILE);
    Error(ERROR_LEVEL_2, argv[0], messageStr);
  }
  
  getLine(fp_ray, COMMENT_CHAR, inputLine, exit_on_EOF=TRUE);
  Nread = sscanf(inputLine, "%lf", &muz);
  checkNread(Nread, Nrequired=1, argv[0], checkPoint=1);

  if (muz <= 0.0  ||  muz > 1.0) {
    sprintf(messageStr,
	    "Value of muz = %f does not lie in interval <0.0, 1.0]\n", muz);
    Error(ERROR_LEVEL_2, argv[0], messageStr);
  }

  if (input.StokesMode == FIELD_FREE ||
      input.StokesMode == POLARIZATION_FREE) {
    input.StokesMode = FULL_STOKES;
  }
  /* --- redefine geometry for just this one ray --    -------------- */

  atmos.Nrays = geometry.Nrays = 1;
  geometry.muz[0] = muz;
  geometry.mux[0] = sqrt(1.0 - SQ(geometry.muz[0]));
  geometry.muy[0] = 0.0;
  geometry.wmu[0] = 1.0;
  if (atmos.Stokes) Bproject();

  input.startJ = OLD_J;

  readAtomicModels();
  readMolecularModels();
  SortLambda();

  getBoundary(&geometry);

  /* --- Open file with background opacities --        -------------- */

  if (atmos.moving || input.StokesMode) {
    strcpy(input.background_File, "background.ray");
    Background(analyze_output=FALSE, equilibria_only=FALSE);
  } else {
    Background(analyze_output=FALSE, equilibria_only=TRUE);

    if ((atmos.fd_background =
	 open(input.background_File, O_RDONLY, 0)) == -1) {
      sprintf(messageStr, "Unable to open inputfile %s",
	      input.background_File);
      Error(ERROR_LEVEL_2, argv[0], messageStr);
    }
    readBRS();
  }
  convertScales(&atmos, &geometry);

  getProfiles();
  initSolution();
  initScatter();

  getCPU(1, TIME_POLL, "Total initialize");

  /* --- Solve radiative transfer equations --         -------------- */

  solveSpectrum(FALSE, FALSE);

  /* --- Write emergent spectrum to output file --     -------------- */
 
  sprintf(rayFileName, "spectrum_%4.2f", muz);
  if ((fp_out = fopen(rayFileName, "w" )) == NULL) {
    sprintf(messageStr, "Unable to open output file %s", rayFileName);
    Error(ERROR_LEVEL_2, argv[0], messageStr);
  }
  xdrstdio_create(&xdrs, fp_out, XDR_ENCODE);

  result = xdr_double(&xdrs, &muz);
  result = xdr_vector(&xdrs, (char *) spectrum.I[0], spectrum.Nspect,
		      sizeof(double), (xdrproc_t) xdr_double);

  /* --- Read wavelength indices for which chi and S are to be
         written out for the specified direction --    -------------- */

  Nread = fscanf(fp_ray, "%d", &Nspect);
  checkNread(Nread, 1, argv[0], checkPoint=2);

  if (Nspect > 0) {
    wave_index = (int *) malloc(Nspect * sizeof(int));
    Nread = 0;
    while (fscanf(fp_ray, "%d", &wave_index[Nread]) != EOF) Nread++;
    checkNread(Nread, Nspect, argv[0], checkPoint=3);
    fclose(fp_ray);

    chi = (double *) malloc(atmos.Nspace * sizeof(double));
    if (atmos.Stokes)
      S = (double *) malloc(4 * atmos.Nspace * sizeof(double));
    else
      S = (double *) malloc(atmos.Nspace * sizeof(double));
  }
  result = xdr_int(&xdrs, &Nspect);

  /* --- Go through the list of wavelengths --         -------------- */

  if (Nspect > 0  &&  input.limit_memory)
    J = (double *) malloc(atmos.Nspace * sizeof(double));

  for (n = 0;  n < Nspect;  n++) {
    if (wave_index[n] < 0  ||  wave_index[n] >= spectrum.Nspect) {
      sprintf(messageStr, "Illegal value of wave_index[n]: %4d\n"
	      "Value has to be between 0 and %4d\n", 
	      wave_index[n], spectrum.Nspect);
      Error(ERROR_LEVEL_2, argv[0], messageStr);
      continue;
    }
    sprintf(messageStr, "Processing n = %4d, lambda = %9.3f [nm]\n",
	    wave_index[n], spectrum.lambda[wave_index[n]]);
    Error(MESSAGE, NULL, messageStr);

    as = &spectrum.as[wave_index[n]];
    alloc_as(wave_index[n], crosscoupling=FALSE);
    Opacity(wave_index[n], 0, to_obs=TRUE, initialize=TRUE);
    readBackground(wave_index[n], 0, to_obs=TRUE);

    if (input.limit_memory) {
      readJlambda(wave_index[n], J);
    } else
      J = spectrum.J[wave_index[n]];

    /* --- Add the continuum opacity and emissivity -- -------------- */   

    for (k = 0;  k < atmos.Nspace;  k++) {
      chi[k] = as->chi[k] + as->chi_c[k];
      S[k]   = (as->eta[k] + as->eta_c[k] + as->sca_c[k]*J[k]) / chi[k];
    }
    result = xdr_int(&xdrs, &wave_index[n]);
    result = xdr_vector(&xdrs, (char *) chi, atmos.Nspace,
			sizeof(double), (xdrproc_t) xdr_double);
    result = xdr_vector(&xdrs, (char *) S, atmos.Nspace,
			sizeof(double), (xdrproc_t) xdr_double);

    free_as(wave_index[n], crosscoupling=FALSE);
  }

  /* --- If magnetic fields are present --             -------------- */
  
  if (atmos.Stokes || input.backgr_pol) {
    result = xdr_vector(&xdrs, (char *) spectrum.Stokes_Q[0],
			spectrum.Nspect, sizeof(double),
			(xdrproc_t) xdr_double);
    result = xdr_vector(&xdrs, (char *) spectrum.Stokes_U[0],
			spectrum.Nspect, sizeof(double),
			(xdrproc_t) xdr_double);
    result = xdr_vector(&xdrs, (char *) spectrum.Stokes_V[0],
			spectrum.Nspect, sizeof(double),
			(xdrproc_t) xdr_double);
  }

  if (Nspect > 0  &&  input.limit_memory)
    free(J);

  xdr_destroy(&xdrs);
  fclose(fp_out);
  printTotalCPU();
}